Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: GB, MB, KB and on..

by ysth (Canon)
on Jul 30, 2004 at 03:26 UTC ( #378580=note: print w/ replies, xml ) Need Help??


in reply to GB, MB, KB and on..

sub scaledbytes { (sort { length $a <=> length $b } map { sprintf '%.3g%s', $_[0]/1024**$_->[1], $_->[0] } [" bytes"=>0],[KB=>1],[MB=>2],[GB=>3],[TB=>4],[PB=>5],[EB=>6])[0] }
Update: don't need none of those stinkin' semicolons. Feels kind of funny to use %g but filter out all the exponential forms (unless that's all there are).


Comment on Re: GB, MB, KB and on..
Download Code
Replies are listed 'Best First'.
Re^2: GB, MB, KB and on..
by BrowserUk (Pope) on Jul 30, 2004 at 04:26 UTC

    Different :)

    One interesting side effect of the sort is that zero length files get listed as 0KB rather than 0 bytes.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2015-07-31 15:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls