Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Perl script to print Next line after Pattern Matching

by NetWallah (Canon)
on Dec 20, 2011 at 14:41 UTC ( [id://944404]=note: print w/replies, xml ) Need Help??


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

Since you had requested it, here is a corrected version of your program:
use strict; use warnings; my $in_file = 'check.doc'; open my $in_fh, '<', $in_file or die "Could not open file $in_file: $! +"; my $out_file = 'output.txt'; open my $out_fh, '>', $out_file or die "Could not open file $out_file: +$!"; my $print_next = 0; while ( my $line = <$in_fh> ) { if ($print_next){ print $out_fh $line; #No need to chomp - we print the "\n" } $print_next = ($line =~ /^Customer ID: Yes/); } close $in_fh or die "Could not close file $in_file: $!"; close $out_fh or die "Could not close file $out_file: $!";
You can add the other features using code that is posted above.

BTW, congrats on using the "correct" form of "open" and "close".

            "XML is like violence: if it doesn't solve your problem, use more."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://944404]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2024-04-23 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found