I have following while using nextline. Bascially, i am parsing some string(N here) in the second line after matching the target. e.g.
And i apply this to find a couple of variables. The code i have at hand is:(line1) target some text here (line2) some more text here N
#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |