Welcome to the Monastery.

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:


In reply to Re: Find next line by toolic
in thread Find next line by toddgow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.