Re: RFC Format::FileSize

2003-08-30 Thread A. Pagaltzis
* Michel Rodriguez [EMAIL PROTECTED] [2003-08-27 20:04]:
 So maybe Number::Format::FileSize ?

I say Number::Format::ByteSize - it can be used to format
anything whose size or capacity is expressed in bytes, be that a
file, a disk, the computer's RAM, a process, a scalar or
anything.

-- 
Regards,
Aristotle
 
If you can't laugh at yourself, you don't take life seriously enough.


Re: RFC Format::FileSize

2003-08-30 Thread Smylers
A. Pagaltzis writes:

 * Michel Rodriguez [EMAIL PROTECTED] [2003-08-27 20:04]:
 
  So maybe Number::Format::FileSize ?
 
 I say Number::Format::ByteSize

That makes a great deal of sense.  It also prompted me into thinking of
Number::Format::Bytes, which is slightly shorter and probably just as
meaningful (if bytes are the unit of something then you should be able
to work out that it's a size).

 - it can be used to format anything whose size or capacity is
 expressed in bytes, be that a file, a disk, the computer's RAM, a
 process, a scalar or anything.

Indeed.

Smylers



Re: RFC Format::FileSize

2003-08-28 Thread Michel Rodriguez
On Wed, 27 Aug 2003, Lars Thegler wrote:

  I just emailed the author

 A worthy effort, indeed :)

At least I will have gained a better knowledge of CPAN ;--)

 While you are at it, you might want to support the whole range of SI
 prefixes (note that these are *not* units, but unit *prefixes*), check out
 http://physics.nist.gov/cuu/Units/prefixes.html to get them all.

 And be very careful; not everybody will agree with you that 'M' should mean
 1024*1024 - communications people will insist that 64kbps is infact 64*10^3
 bps, and not 64*2^10 bps. IEC tried to define new names (kibi instead of
 kilo for 2^10), but I seriously doubt that these will ever get wider
 accceptance.

The primary use of this module is to display file sizes. It can certainly
also display memory sizes, but anything else, while possible (you can
configure the units, their relation and so on...) would probably be a
stretch.

I like the Gibi (the Gibis were a race in a French cartoon that I loved as
a kid: http://perso.club-internet.fr/wabnitz/Shadok/Shadok.htm (French))

 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 :)

You can configure the factor used, not to that level though, I would have
either to include this as a special case or to allow complete
customization of the unit table.

Maybe adding styles for other units would be a good option, if indeed I
release the module, which seems doubtfull at this point.

Michel Rodriguez
Perl amp; XML
http://www.xmltwig.com



RFC Format::FileSize

2003-08-27 Thread Michel Rodriguez
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

2003-08-27 Thread Orton, Yves
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

2003-08-27 Thread Mark Stosberg
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

2003-08-27 Thread Michel Rodriguez
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

2003-08-27 Thread Kate L Pugh
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

2003-08-27 Thread Paul Johnson
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