Skip to content

Instantly share code, notes, and snippets.

@karupanerura
Created March 28, 2011 15:02
Show Gist options
  • Save karupanerura/890622 to your computer and use it in GitHub Desktop.
Save karupanerura/890622 to your computer and use it in GitHub Desktop.
ファイル名と行番号を付加してテキストを出力。grepと組み合わせる事を想定。
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