Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Pretty text reports with perl

by tsk1979 (Scribe)
on Jun 08, 2009 at 11:35 UTC ( [id://769459]=perlquestion: print w/replies, xml ) Need Help??

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

I have a perl program which processes some data from RAW files, and creates hashes. Now at the end, I need to show the user column reports For example
Total Value (%) Count MIN MAX ========================================== 500 43 (98%) 340 4 18
Now data can change, for example 43 can become 1456, and in case of fixed formatting, reports appear ugly.

Is there a way of good formatting so that the data is always printed "centered" or something.
Cannot think of a good formatting scheme, Looked up some articles, but noone talks about pretty printing with perl. Help please

Replies are listed 'Best First'.
Re: Pretty text reports with perl
by toolic (Bishop) on Jun 08, 2009 at 12:27 UTC
Re: Pretty text reports with perl
by wfsp (Abbot) on Jun 08, 2009 at 12:25 UTC
      Thanks, I used pack, and its working perfectly. I created a format string and stored in in a variable. Everywhere I use format string. So all reports have the same look and feel!
Re: Pretty text reports with perl
by JavaFan (Canon) on Jun 08, 2009 at 11:56 UTC
    Centered? I always assumed people want their numbers to be right aligned (or on the decimal dot, if any).

    Instead of the previously suggested formats, you might want to consider (s)printf.

Re: Pretty text reports with perl
by targetsmart (Curate) on Jun 08, 2009 at 11:37 UTC
    from perlform
    > pad character for right adjustification
    you can use like @>>>>, it can handle 43 as well as your 1456

    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
      If you use the format construction, you can center values by specifying vertical bars.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-25 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found