Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Reading certain lines in a file

by mrmick (Curate)
on May 24, 2001 at 18:33 UTC ( #82923=note: print w/ replies, xml ) Need Help??

in reply to Reading certain lines in a file

How about the following(untested, of course):

# read a file and set a flag (boolean) if pattern is found # we then will print the following line and reset the flag open(OUT,$outputfilename)||die "Could not open $outputfilename for out +put\n$!\n"; open(FILE,$inputfilename)||die "Could not open $inputfilename for read +ing\n$!\n"; while(<FILE>){ if($checked){ print OUT; undef $checked; next; } if(/pattern/){ $checked=1; next; } } close(FILE); close(OUT);


Comment on Re: Reading certain lines in a file
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2015-11-28 05:11 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (737 votes), past polls