Two Perl features I'd like to see

TorgoX on 2002-02-14T13:20:50

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.


More Important

pudge on 2002-02-14T13:41:23

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

What *I* would really like...

djberg96 on 2002-02-14T14:22:11

...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.

too many choices

jmm on 2002-02-14T15:47:37

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 own and have as many formats as you have object types for each letter of the alphabet.

Encoding Detection

Matts on 2002-02-14T17:34:22

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