in reply to Zero Padding
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?
#!/usr/bin/perl -wl use strict; my @numberarray = qw(1 120 13); lengthy(@numberarray); sub lengthy { s{ ( ^ ) } { ( "0" x (6-length $_) ) }xe and print for @_; } __END__
(Sir...put your hands up and please, step away from the keyboard)
One more.. to pad words with spaces, instead of zeros.
perl -wle ' s/^(\d+)/("0"x(6-length).$1)/xe and print or s/^(\w)/("\x20"x(6-length).$1)/xe and print for @ARGV;' 133 121 10 + 13 red
|
|---|