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 ]

TorgoX (1933)

TorgoX
  sburkeNO@SPAMcpan.org
http://search.cpan.org/~sburke/

"Il est beau comme la retractilité des serres des oiseaux rapaces [...] et surtout, comme la rencontre fortuite sur une table de dissection d'une machine à coudre et d'un parapluie !" -- Lautréamont

Journal of TorgoX (1933)

Thursday February 14, 2002
08:20 AM

Two Perl features I'd like to see

[ #2856 ]
Dear Log,

What I'd really like to be added to Perl:

I'd like if there were a %C sprintf format that was like %g, but also did commafication on the integer part of the number(well, with a locale-specific thousands separator, so you get "." or " " as locale-appropriate). So I can just do printf "That file uses %C bytes.\n", -s $filename; and have it say, for example, That file uses 10,116,911 bytes.
(I know it would be a Good Thing if all of sprintf were rewritten to allow, say, overloading specific sprintf formats. But I see reason to wait for that. If I knew any C, I'd just have done this myself years ago and submitted the patch; but I don't know C.)

Another thing I'd really like:

I'd like if there were a file read-discipline that would auto-guess the encoding (at least as either UTF-8, UTF-16, or other), and also auto-guess the newline format.

For some reason, I'm in a particularly foul mood today, so I hereby threaten to put an ice-axe thru the forehead of anyone who wants to tell me that these things don't belong in the Perl core.

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.
  • More Important (Score:2, Informative)

    would be to finish implementing *all* of sprintf in perl's core. For example, %g is broken in the version of sfio that MacPerl uses, and perl doesn't implement %g, though it implements many of the others.

    That said, %C seems like a decent idea to me, but it makes me think of what other formats we might want. Maybe a format for HTML encoding or URI encoding of a string? :-)/2
  • ...is a working, stable thread model.

    Occasionally I tinker with the notion of fork'ing some of my apps where I think I could get some extra speed, but then the reality of overhead hits me.

  • The alphabet is too small for the number of formats you might want. (The example of memory given is wrong - memory you want to be displayed with 3 or 4 characters of accuracy and variable units automatically switching amongst B, KB, MB, GB, ...)

    I think that it would be better for printf to check whether the value to be printed is an object which has a printf method. If it does, it gets called something like:

          $val->printf( width, prec, format, flags )

    That lets you roll your ow
  • I've done this for UTF16/UCS2 (both little and big endian), UTF32/UCS4 (again, both ends ;-), and UTF8, using byte order marks, for XML::SAX::PurePerl. It should be fairly easy to extract the code and stuff into the I/O layer.

    But it really shouldn't go in perl core... :-)