Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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);

Mick

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2016-10-01 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (6 votes). Check out past polls.