in reply to Regular Expression Help
If you want to use a substitution, you could do:$u = sprintf "%06d", $u;
Update: To correct your attempt:$u =~ s/(\d+)/"0"x(6-length($1)).$1/e; if length($u) < 6;
if($u=~/^\d{4}$/){$u=~s/\d\d\d\d/00$u/;} if($u=~/^\d{5}$/){$u=~s/\d\d\d\d\d/0$u/;} # but better written as: # $u = "00$u" if $u =~ /^\d{4}$/; # $u = "00$u" if length($u) == 4; # if you know it's digits
|
|---|