Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: pretty print bytes

by seanbo (Chaplain)
on Apr 05, 2002 at 14:45 UTC ( [id://156933]=note: print w/replies, xml ) Need Help??


in reply to pretty print bytes

I use something like this. I was considering writing some small CPAN module and making this better...not sure how usable an entire module would be though.
sub round_it { my $num = shift; my $gb = (1024 * 1024 * 1024); my $mb = (1024 * 1024); my $kb = 1024; ($num > $gb) ? return sprintf("%dGB", $num/$gb) : ($num > $mb) ? return sprintf("%dMB", $num/$mb) : ($num > $kb) ? return sprintf("%dKB", $num/$kb) : return $num . 'B'; }

Anybody have any comments or suggestions?

Update: I think I stole some (or all?) of this code from merlyn sometime back...don't really remember.

perl -e 'print reverse qw/o b n a e s/;'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-19 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found