[Omaha.pm] find "000" in position 70-72 in text files

Andy Lester andy at petdance.com
Mon Apr 9 11:39:53 PDT 2007


> my @files = glob "*dly";
> foreach my $file (@files) {
>    open (IN, $file);
>    while (<IN>) {
>       if (/^.{69}000/) {
>          print "$file: $_";
>       }
>    }
>    close IN;
> }

Jay, please start usin' the lexical handles!  So you can say

	open( my $IN, $file ) or die "Can't open $file: $!\n";

Using the old-style handles is dangerous.


You can also shorten it reaaaally short like so:

	$ perl -lne'print "$ARGV: $_" if /^.{69}000/' *dly

That "open the file, read it and loop over it" is very common, and  
command line flags make it even easier.

--
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance






More information about the Omaha-pm mailing list