in reply to Find next line

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:

Replies are listed 'Best First'.
Re^2: Find next line
by toddgow (Initiate) on Feb 02, 2009 at 21:09 UTC
    Toolic, Thanks so much for taking the time to look at this and the recomendations. Here is a snippet from my XML file:
    <script type="ApplicationPerspective" version="5.3.13.179" recorder="8 +.6.59.276" sav="25" guid="296A95D0-E8B6-4989-AA21-126796A3AD3F" xmlns +="http://www.keynote.com/namespaces/tstp/script"> <name> <![CDATA[GT Amadeus]]> </name> ....... <actions> <action FrameErrorFatal="1" MetaErrorFatal="1"> <name> <![CDATA[Home Page]]> </name> <description> <![CDATA[]]> </description>
    I have started looking at XML:Twig. I need to be able to pull the CDATA in between the <name> tags. Here is my sample XML:Twig code right now:
    #!/usr/bin/perl use XML::Twig; my $file = $ARGV[0]; my $twig= new XML::Twig(TwigRoots => {script/name' => 1}); $twig->parsefile($file); $twig->print;
      Something like this?
      use strict; use warnings; use XML::Twig; my $xmlStr = <<XML; <script type="ApplicationPerspective" version="5.3.13.179" recorder="8 +.6.59.276" sav="25" guid="296A95D0-E8B6-4989-AA21-126796A3AD3F" xmlns +="http://www.keynote.com/namespaces/tstp/script"> <name> <![CDATA[GT Amadeus]]> </name> <actions> <action FrameErrorFatal="1" MetaErrorFatal="1"> <name> <![CDATA[Home Page]]> </name> <description> <![CDATA[]]> </description> </action> </actions> </script> XML my $twig = new XML::Twig( twig_handlers => { name => \&name } ); $twig->parse($xmlStr); sub name { my ($twig, $name) = @_; my $stuff = $name->text(); print "$stuff\n"; } __END__ GT Amadeus Home Page
        Thanks again. This is pointing me in the right direction. I really appreciate it. Regards, Todd