Beefy Boxes and Bandwidth Generously Provided by pair Networks Russ
We don't bite newbies here... much
 
PerlMonks  

Supressing zero values in formatted reports

by ryan (Pilgrim)
on Dec 28, 2001 at 13:18 UTC ( #134831=perlquestion: print w/ replies, xml ) Need Help??
ryan has asked for the wisdom of the Perl Monks concerning the following question:

I am using formatting to output some information, I was wishing to supress the display of all zero (0) values.

Setting the variables concerned to blank '' or undefing them only causes errors.
format top = User Emails Size (Kb) ============== ======== =========== . format DISPLAY = @<<<<<<<<<<<<< @#### @#####.## $output[$i], $output[$i+1], $output[$i+2]/1024 .
Can it be done?

Thanks ... Ryan

Comment on Supressing zero values in formatted reports
Download Code
Re: Supressing zero values in formatted reports
by Fengor (Monk) on Dec 28, 2001 at 14:04 UTC
    From the perfunc page of format:
    format Something = Test: @<<<<<<<< @||||| @>>>>> $str, $%, '$' . int($num) . $str = "widget"; $num = $cost/$quantity; $~ = 'Something'; write;
    so maybe u can do something like:
    format top = User Emails Size (Kb) ============== ======== =========== . format DISPLAY = @<<<<<<<<<<<<< @#### @#####.## $temp[$i], $temp[$i+1], $temp[$i+2] . if ($output[$i]) {$temp[$i]=$output[$i]} else {$temp[$i]==' '} if ($output[$i+1]) {$temp[$i+1]=$output[$i+1]} else {$temp[$i+1]==' '} if ($output[$i+2]) {$temp[$i+2]=$output[$i+2]/1024} else {$temp[$i+2]==' '}
    hth
    fengor

    --
    "WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
    -- Terry Pratchett, "Reaper Man"

      Thanks, however that causes the same Argument " " isn't numeric in formline error that setting it to blank does.
        Hmm this isn't an error. It's a warning.

        From perldiag: Argument "%s" isn't numeric%s

        (W) The indicated string was fed as an argument to an operator that expected a numeric value instead. If you're fortunate the message will identify which operator was so unfortunate.

        This means although the warning is displayed your program should run normally.

        hth
        fengor

        --
        "WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
        -- Terry Pratchett, "Reaper Man"

Re: Supressing zero values in formatted reports
by robin (Chaplain) on Dec 28, 2001 at 15:41 UTC
    From the perlform manpage:
    Picture fields that begin with ^ rather than @ are treated specially. With a # field, the field is blanked out if the value is undefined. For other field types, the caret enables a kind of fill mode.
    So change your @#### to ^####, and make sure the values you want to suppress are undefined.

    The second problem is that using an undefined value when warnings are enabled will generate several warning messages. I suggest disabling warnings within the format, like this:

    { no warnings; format STDOUT = @<<<<<<<<<<<<< ^#### @#####.## $output[$i], $output[$i+1], $output[$i+2]/1024 . }
      hmm guess i should read more carefully next time ;-)

      thx
      fengor

      --
      "WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
      -- Terry Pratchett, "Reaper Man"

      That works, thanks for that, I must try to search more for the answers for these things. I did a lot of searching in the wrong places :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (17)
As of 2014-04-16 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (429 votes), past polls