Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Perl reports

by semio (Friar)
on Oct 18, 2002 at 17:52 UTC ( #206382=perlquestion: print w/replies, xml ) Need Help??

semio has asked for the wisdom of the Perl Monks concerning the following question:

fellow monks,

A few months ago I submitted a piece a code and jeffa helped me out immensely by pointing me to Perltidy. Stylistically, I know I have much room for improvement. One thing I'm hoping to improve upon is the presentation of data as produced by my scripts. The following section of code presents a simple example.

open( WEBLOG, ">$log" ); print WEBLOG "====================\n"; foreach $string (@strings) { chomp $string; $string = "$string" . " HTTP/1.0\012\012"; my $sock = IO::Socket::INET->new( PeerAddr => $host, PeerPort => $port, Proto => $proto ); print $sock "$string"; while (<$sock>) { push @page, $_; } if ( $page[0] =~ m/404/ ) { chomp $string; print WEBLOG $string; print WEBLOG "====================\n"; } @page = (); } close(WEBLOG);
and this would produce the following output:
==================== GET /FOO HTTP/1.0 ==================== GET /FOOBAR HTTP/1.0 ====================
I am looking for a better way to present data such as this, e.g include a document title, page numbers, and multiple columns if appropriate. Currently, my formatting skills are limited to printing a series of characters to separate the output. Is there a better way? Any assistance will be greatly appreciated.

cheers, -semio

Replies are listed 'Best First'.
Re: Perl reports
by ignatz (Vicar) on Oct 18, 2002 at 18:10 UTC
    Formats is the place you want be, so load up your truck and go to the perlform man page or Chapter 7 in the must have Camel book. Printing out pretty ASCII reports is old hat for Perl.
Re: Perl reports
by Enlil (Parson) on Oct 18, 2002 at 18:08 UTC
    Try looking here:


    Which is what I have used in the past for some presentation issues with my output in reports.


Re: Perl reports
by gjb (Vicar) on Oct 18, 2002 at 23:58 UTC

    I take it you actually want an output that looks as if it were produced by a word processor, rather than fancy looking ASCII art. If so, Perl forms may not be what you want.

    You could consider generating an HTML document rather than plain text. There are several CPAN modules to help you do this. Such an approach would give you all but page numbers.

    Taking things a step further, you might want to convert the HTML file to LaTeX (or generate LaTeX directly if you know how to).

    If fancy ASCII is what you want, I'd advice against going for Perl forms, but rather use a modern template toolkit such as Text::Template. It allows to separate code from presentation which is a better approach than mixing the two IMHO.

    Hope this helps, -gjb-

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://206382]
Approved by fglock
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2023-06-07 00:20 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (29 votes). Check out past polls.