Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Read block of file and print to html table

by sundialsvc4 (Abbot)
on Nov 28, 2011 at 13:09 UTC ( [id://940395]=note: print w/replies, xml ) Need Help??


in reply to Read block of file and print to html table

When dealing with a problem like this, you know that you want to write “maintainable” code that will Do The Right Thing™ without being flummoxed by (inevitable...) slight differences (glitches) in the input data.   So, the general structure of the program might be:

open_files(); write_table_header(); while (my $row = read_next_record()) { output_table_row($row); } write_table_footer(); close_files();

The next “interesting” part is to consider the various forms that the input lines may take.   Such as:

  1. End of file has been reached.
  2. Blank line.
  3. tag: value
  4. None of the above (garbage line)

The read_next_record() routine treats the input as consisting of a stream of one of these four line-types, and it must work correctly in all cases including empty-file.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://940395]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-29 10:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found