Hi qingxia. With respect to those monks who have already replied and are correctly trying to convince you to consider a different approach to parsing even simple HTML, I think you need to start at the beginning before doing that. The very beginning consists of learning how to read documentation and placing these lines at the top of every program you work on, unless you know why you are leaving them out.

use strict; use warnings;

In addition to strict and warnings, you may wish to add diagnostics as well.

use strict; use warnings; use diagnostics;

If you do this on your current program, you'll find it won't compile until make some simple changes. Specifically, you'll need to declare your variables with my, which can be done as follows (but be aware that automatically declaring all variables at file scope like this is NOT in general good programming practice).

my $Borrower = "null"; my $activeDate = "null"; my $Amount = "null"; my $on = 0; my $line; my $nextline;

Once you've made these changes, the Perl interpreter will be able to help you by giving feedback when you edit your code in certain problematic ways it can identify. It is standard and highly recommended to enable 'strict' and 'warnings'.

Next, it is the responsibility of a programmer to know what each line of code is doing, and to read the relevant documentation when necessary. You use the expression <FILE> both in a while loop and in nested if blocks, which is sure to be confusing even if you somehow manage to get the code to do what you want. On top of that you are assigning its value to two different variables, $line and $nextline, thereby creating more confusion. Do some reading about syntax, and specifically next for better ideas. Perl syntax is rich, and with some reading and experimentation you ought to be able to easily replace what you are trying to do with your clunky variable $on with much clearer code and you may be able to see just why you aren't getting the results you desire.

Standard recommended programming practices recommend that functionally distinct ideas be separated into different blocks of code. So structuring your program to both process a file and provide output in the same block is likely going to hinder the ability to improve it. Instead, try to rewrite it with better structure.

pseudocode: while ( <FILE> ) { do_stuff_to_process_file(); get_needed_info(); } do_output_related_stuff_outside_the_above_block();


In reply to Re: $nextline not working by farang
in thread $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.