![]() |
|
Don't ask to ask, just ask | |
PerlMonks |
Re: Zero Paddingby mkmcconn (Chaplain) |
on Feb 03, 2001 at 22:40 UTC ( #56238=note: print w/replies, xml ) | Need Help?? |
Variation on a theme, with a twist that I don't think has been mentioned. I've tried to do my homework, and nothing stood out that would break this. What do you think?
Or, for the commandline: perl -wle ' s/^/("0"x(6-length))/xe and print for @ARGV;' 133 121 10 13 Or, to make sure that it doesn't zero-pad alphabetical input perl -wle ' s{(^)(\d+$)}{("0"x(6-length).$2)}xe and print for @ARGV;' 1 fish 002 fish 333 blue fish And, to print all the arguments, but zero-padding only the numerical arguments: perl -wle ' s{(^)(\d+$)}{("0"x(6-length).$2)}xe and print or print for @ARGV;' 1 fish 002 fish 333 blue fish
(Sir...put your hands up and please, step away from the keyboard)
mkmcconn (I'm gratified by how much better it is than this a few short weeks later. Thanks Perl Monks.).
In Section
Seekers of Perl Wisdom
|
|