in reply to Find next line
Please edit your node to add "code" tags around your code segments because it is difficult to read. See Writeup Formatting Tips. And it is good form to post the actual code that you are using, i.e., code that compiles (you meant die instead of "dir", etc.).
Since parsing XML is tricky business, it is a good idea to use one of the CPAN modules to do it for you. There is a learning curve, but it's well worth the effort. I recommend XML::Twig.
Having said that, one way to get the next line after a matching line is to use a while loop instead of a foreach loop, as follows (untested):
while (<>) { if (/name/) { print; my $next_line = <>; # do something with $next_line ... } }
Some more miscellaneous observations:
open my $fh, '<', $file or die "can not open $file: $!"; while <$fh> { ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Find next line
by toddgow (Initiate) on Feb 02, 2009 at 21:09 UTC | |
by toolic (Bishop) on Feb 03, 2009 at 17:51 UTC | |
by toddgow (Initiate) on Feb 05, 2009 at 23:33 UTC |