hi monkers:

I have following while using nextline. Bascially, i am parsing some string(N here) in the second line after matching the target. e.g.

(line1) target some text here (line2) some more text here N
And i apply this to find a couple of variables. The code i have at hand is:
#!/usr/bin/perl print "Borrower\tactiveDate\tAmount\n"; $Borrower = "null"; $activeDate = "null"; $Amount = "null"; $on = 0; open(FILE, $ARGV[0]); while ($line = <FILE>) { if ($on eq 0 and $line =~ /<tr/) { $on = 1; } if ($on eq 1) { if ($line =~ /<div(.*?)>Borrower:<\/td>/) { $nextline = <FILE>; if ($nextline =~ /<td(.*?)>(.*?)(\s)/) { $Borrower = $2;} if ($nextline =~ /<td(.*?)>(.*?)<\/td>/) { $Borrower = $2;} } if ($line =~ /(\s)active(\s)date\:<\/td>/) { $nextline = <FILE>; if ($nextline =~ /<td(.*?)>(.*?)<\/td>/) { $activeDate = $2;} } if ($line =~ /<td(.*?)>Amount:<\/td>/) { $nextline = <FILE>; if ($nextline =~ /<td(.*?)>(.*?)(\s)/) { $Amount = $2;} if ($nextline =~ /<td(.*?)>(.*?)<\/td>/) { $Amount = $2;} } } if ($line =~ /<\/tr>/) { $on = 0; if ($Borrower ne "null") { print "$Borrower\t$activeDate\t$Amount\n"; $Borrower = "null"; $activeDate = "null"; $Amount = "null"; } } } close(FILE);

the code goes well for the first variable namely 'borrower', however it starts going wrong from the rest. It is 'null' for the first 'borrower' in the variables 'activedate' and 'Amount', and one position lagged matched for the rest. i.e. the right 'activedate' and 'Amount' value of first borrower goes to the second borrower, the second goes to the third, so on and so forth.

Stuck for a while, hope someone help me out of here. thanks a lot in advance. regards,

In reply to $nextline not working by qingxia

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.