Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Perl script to print Next line after Pattern Matching

by mr.nick (Chaplain)
on Dec 20, 2011 at 13:45 UTC ( [id://944394] : note . print w/replies, xml ) Need Help??


in reply to Perl script to print Next line after Pattern Matching

Quick'n'dirty:
use strict; use warnings; for my $file (<*.doc>) { open my $fh, "<", $file or die $!; while (<$fh>) { print scalar <$fh> if /^Customer ID: Yes/; } }

For #2, you can write out a tab delimited file named "output.xls" and Excel will automatically convert it upon load.

mr.nick ...

Replies are listed 'Best First'.
Re^2: Perl script to print Next line after Pattern Matching
by jwkrahn (Abbot) on Dec 20, 2011 at 22:05 UTC

    Also quick'n'dirty:

    use strict; use warnings; @ARGV = <*.doc>; while ( <> ) { print scalar <> if /^Customer ID: Yes/; }
      I recognize that. So the point is to loop over the file handle; extract the next part when the current part is interesting.
        Should have added above that that works only because the same file handle being used in two places in the same loop does not go out of whack, and state is retained on the next iteration.