Created
March 28, 2011 15:02
-
-
Save karupanerura/890622 to your computer and use it in GitHub Desktop.
ファイル名と行番号を付加してテキストを出力。grepと組み合わせる事を想定。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.12.1; | |
use common::sense; | |
use Path::Class qw(file); | |
use File::Spec; | |
use File::Basename; | |
my $dir = File::Spec->rel2abs(dirname(__FILE__)); | |
my @files; | |
if(@ARGV){ | |
@files = @ARGV; | |
}else{ | |
say("Usage: $0 filepath"); | |
exit; | |
} | |
foreach my $file (@files){ | |
my $fh = file($dir, $file)->openr(); | |
my $line = 1; | |
say '-' x 10 . $file . ' start ' . '-' x 10; | |
printf("%s:%04d: %s", $file, $line++, $_) while(<$fh>); | |
say '-' x 10 . $file . '- end -' . '-' x 10; | |
} | |
exit; | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment