WingedKnight
Programmer
Suppose you have an integer $n and you want to add enough leading zeroes to that integer to make it a certain width in characters (for the examples below, let's say a width of 5.) I'm well aware that this can be done with such ways as
The above statements can be converted into regex form:
Is there any way to add leading zeroes with a single-line regex substitution without using the "/e" option?
Code:
$n = sprintf("%05d", $n);
$n = substr(0 x 5 . "$n", -5);
The above statements can be converted into regex form:
Code:
$n =~ s/(\d+)/sprintf("%05d", $1)/e;
$n =~ s/(\d+)/substr(0 x 5 . "$1", -5)/e;
Is there any way to add leading zeroes with a single-line regex substitution without using the "/e" option?