Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-20 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found