Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

chromatic (983)

chromatic
  (email not shown publicly)
http://wgz.org/chromatic/

Blog Information [technorati.com] Profile for chr0matic [technorati.com]

Journal of chromatic (983)

Thursday August 28, 2003
08:51 PM

A Stupid Little Module?

[ #14377 ]

I've been overworked for months. I'm on the road this week. I spoke at a user group meeting last night and spent nearly four hours driving back and forth just to get to the hotel late and I overslept a bit.

These are probably not opportune times to be coding, but adding nicer directory listings to Jellybean, I wondered if there was a module to convert file sizes in raw bytes to nicer suffixed equivalents. Not finding anything called File::Size in the first ten pages of CPAN results, I threw together some tests and wrote my own:

sub describe_size
{
    my $size = shift;

    return $size if $size < 1024;

    for my $unit (qw( k M G T P E ))
    {
        $size  /= 1024;
        return int( $size ) . $unit if $size < 1024;
    }
}

There's an elegance I like, but if it's not so useful, I won't package it for the CPAN. Opinions? (If you saw an earlier version that skipped terabytes and petabytes, I've already fixed that!)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.