TIMTOWTDI (though sprintf is faster):
sub pad_zeros { my $optimal_length = 5; my $num = shift; $num =~s/^(\d+)$/("0"x($optimal_length-length$1)).$1/e; return $num; }
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) Re: front-pad a number with zero's
by Ovid
in thread front-pad a number with zero's
by deprecated
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |