RFC Format::FileSize
Hi, I was processing a bunch of files the other day, and I wanted to get a rough idea of their size. Oddly enough I could not find anything that seemed to be doing this. So I wrote Format::FileSize, which exports 1 function, named formatted_size, perl -MFormat::FileSize -le'foreach (@ARGV) { printf %-12d = %s\n, $_, formatted_size( $_) }' \ 0 1 500 1023 1024 1025 2500 25000 \ 25 100 2500 25000 \ 25 0= 0 1= 1 500 = 500 1023 = 1023 1024 = 1 K 1025 = 1 K 2500 = 2.44 K 25000= 24.4 K 25 = 244 K 100 = 976 K 2500 = 23.8 M 25000= 238 M -1794967296 = 2.32 G Does this make sense or does this already exist and I have missed it? Is Format::FileSize a proper name? A first version is available at http://www.xmltwig.com/module/format-filesize/ Thanks Michel Rodriguez Perl amp; XML http://www.xmltwig.com
RE: RFC Format::FileSize
Title: RE: RFC Format::FileSize 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. But im not going to stick my neck out with something better cause im not talented that way either. :-) Yves
Re: RFC Format::FileSize
On Wed, Aug 27, 2003 at 05:55:49PM +0100, 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 agree FileSize is not a good name, because the module appears to deal with unit conversion and display, which could be for something besides file size. I think like idea of checking the unit name space. Mark
RE: RFC Format::FileSize
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 25 100 2500 25000 25 0= 0 1= 1 500 = 500 1023 = 1023 1024 = 1 K 1025 = 1 K 2500 = 2.44 K 25000= 24.4 K 25 = 244 K 100 = 976 K 2500 = 23.8 M 25000= 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 25 100 2500 25000 \ 25 0= 0 1= 1 500 = 500 1023 = 1,023 1024 = 1,024 1025 = 1K 2500 = 2.44K 25000= 24.41K 25 = 244.14K 100 = 976.56K 2500 = 23.84M 25000= 238.42M -1794967296 = 2.33G So maybe Number::Format::FileSize ? Michel Rodriguez Perl amp; XML http://www.xmltwig.com
Re: RFC Format::FileSize
On Wed 27 Aug 2003, Michel Rodriguez [EMAIL PROTECTED] wrote: 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. How about you patch Number::Format to do what you want to do? See also Number::Compare for another reason why you probably want to be in Number::* Kake
Re: RFC Format::FileSize
On Wed, Aug 27, 2003 at 11:30:03PM +0200, Lars Thegler wrote: Also, if you look at harddisk capacity figures, some (most) manufacturers will say '80Gb' meaning 80*10^9 bytes, rather than 80*2^30. Makes the disks appear bigger than they are - standard salesman trick :) Insert the old joke about the IBM salesman selling 1K of memory for 1K, and you paying $1024 for 1000 bytes. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net
PAUSE is officially back up
Hi all, Thanks to the efforts of the inimitable Andreas Knig, PAUSE is back online again (many of you probably know this already, but I just remembered that I said I'd announce when things were fixed). And if anybody sees that guy who's been sending all the spam, please slap him for me. - Kurt