Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Lincoln has a CGI.pm manual online. But if you can, grab a copy of Official Guide to Programming wth CGI.pm. It's invaluable as a desktop reference.

As mephit noted, you're already importing all of the standard CGI.pm functions by using use CGI qw(:standard). Since you may as well use what's already imported, below is a sample of what your program can look like with using CGI.pm.

#!/usr/bin/perl -w use strict; use CGI qw/ :standard *table /; use CGI::Pretty; # not necessary, but it makes for more legible html o +utput my $db ="test.txt"; # moved header and start_html outside of loop # print takes a list, so you can join several items to print with comm +as print header, start_html( -title => 'Script' ), hr, start_table( { -width => '100%', -border => '0' } ); # It's more helpful to include $! in the error open( FILE, "<$db" ) or die "Well, whats up.. can't open file $!\n"; while ( <FILE> ) { # no need to define $line here -- $_ is already defined, so you ca +n use it # directly chomp; # Just a preference note. When working with arrays, I prefer to u +se # something a little easier to maintain, like: # my ( $name, $date, $something, $somethingelse ) = split/::/; # it's a bit easier than trying to remember the order of the field +s in $db my @events = split/::/; print Tr( td( { -width => '22%' }, font( { -size => '+1', color => 'gray' }, b( "$events[0] $events[1], $events[2]" ) ) ), td( { -width => '78%' }, font( { -size => '+1', color => 'black' }, $events[3] ) ) ), Tr( td( { -colspan => '2'}, font( { -size => '2' }, $events[4] ) ) ); } print end_table, end_html; close FILE or die "Can't close $!\n";

In reply to Re: Printing with CGI.pm by Jazz
in thread Printing with CGI.pm by cal

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 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? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2021-12-06 23:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (33 votes). Check out past polls.

    Notices?