On Wed, 27 Aug 2003, Orton, Yves wrote: > > Does this make sense or does this already exist and I have missed it? > > Is Format::FileSize a proper name? > > > Do a search for "units" on search.cpan.org and i think youll find this > somewhere. And no I dont think the name is that great.
I just did that, but to no avail. This function does not seem to be available in an existing module. As far as the name goes, I agree that it is not limited to file size, it can also be memory, but that's pretty much it, as least out-of-the-box. You can the configure it to display pretty much anything (not times though, that's something I won't get involved in ;--). But it does not do conversion, it just generates a short string that's meaningful enough for human usage. Quite a few tools use similar algorithms, df, du, and such. It's really just a way to format a number. I actually found that Number::Format has a quite similar function, albeit slightly less configurable. compare: perl -MFormat::FileSize -le'foreach (@ARGV) { printf "%-12d => %s\n", $_, formatted_size( $_) }' 0 1 500 1023 \ 1024 1025 2500 25000 250000 1000000 25000000 250000000 2500000000 0 => 0 1 => 1 500 => 500 1023 => 1023 1024 => 1 K 1025 => 1 K 2500 => 2.44 K 25000 => 24.4 K 250000 => 244 K 1000000 => 976 K 25000000 => 23.8 M 250000000 => 238 M -1794967296 => 2.32 G perl -MNumber::Format -le'foreach (@ARGV) { printf "%-12d => %s\n", $_, Number::Format::format_bytes( $_) }' 0 1 500 1023 1024 1025 2500 25000 250000 1000000 25000000 250000000 \ 2500000000 0 => 0 1 => 1 500 => 500 1023 => 1,023 1024 => 1,024 1025 => 1K 2500 => 2.44K 25000 => 24.41K 250000 => 244.14K 1000000 => 976.56K 25000000 => 23.84M 250000000 => 238.42M -1794967296 => 2.33G So maybe Number::Format::FileSize ? Michel Rodriguez Perl & XML http://www.xmltwig.com