in reply to Reading certain lines in a file
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Nice idea for examples
by John M. Dlugosz (Monsignor) on May 24, 2001 at 21:50 UTC |