Very nice! This requires perl 5.8.0 and above. When I ran it with perl 5.6.1 and perl 5.005 I got the error message:
Update: from perl58delta: "pack() / unpack() can now group template letters with () and then apply repetition/count modifiers on the groups". Also, I think you need to reverse the reverse and scalar. Running:Invalid type in unpack: '(' at g.pl line 3.
produces:use strict; sub commify { reverse scalar join ',', unpack '(A3)*', reverse scalar shift; } sub commify2 { scalar reverse join ',', unpack '(A3)*', reverse scalar shift; } my $x = commify(1234); my $y = commify2(1234); print "x='$x' y='$y'\n"; print "comm :", commify(1234), ":\n"; print "comm2:", commify2(1234), ":\n";
x='1,234' y='1,234' comm :432,1: comm2:1,234:
In reply to Re: Commify numbers, the boring and straightforward way
by eyepopslikeamosquito
in thread Commify numbers, the boring and straightforward way
by Aristotle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |