[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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@petdance.com => www.petdance.com => AIM:petdance