This does what you want
tachyon
# I use the DATA filehandle here # you will need to do an # open(DATA,"<file.txt") || die "Oops $!\n"; # to open your file for reading use strict; my $line; while (<DATA>) { next unless /couldn't parse/; $line = <DATA>; chomp $line; last; } close DATA; if ($line) { print "found line: $line\n"; save($line); } else { print "no line found\n"; } sub save { open (FILE,">>c:/my_stuff.txt") || die "Oops $!\n"; print FILE "$line\n"; close FILE; print "Saved line\n"; } __DATA__ blah blah blah blah blah blah couldn't parse line i want to print blah blah blah blah blah blah
In reply to Re: Reading certain lines in a file
by tachyon
in thread Reading certain lines in a file
by Ras
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |