On Oct 30, 2001 at 13:22 a brother posted a 10 line
snippet to put leading 0's on numbers.
The first 3 responses were:
Re: front-pad a number with zero's
by japhy on Oct 30, 2001 at 13:27
. . .
But honestly, this is a job for sprintf():
sprintf "%0${len}d", $number;
That is, sprintf("%05d", 123) returns 00123.
Re: front-pad a number with zero's
by Masem on Oct 30, 2001 at 13:27
Why not (simply)?:
$string = sprintf( "%05d", $number );
Re: front-pad a number with zero's
by lhoward on Oct 30, 2001 at 13:27
You can do the same thing with sprintf.
my $f=sprintf("%05d",123);
will put "00123" into $f.