in reply to removing leading 0's
Or looked at another way, by the time you do the substitution, it's too late: there are no leading zeroes to remove.
c:\@Work\Perl\monks>perl -wMstrict -le "my $y = 0010; print qq{before: '$y'}; ;; $y =~ s/^0+//; print qq{after: '$y'}; " before: '8' after: '8'
Update: But if you can manage to keep the leading zeroes, as in a string, it all works right.
c:\@Work\Perl\monks>perl -wMstrict -le "my $y = '010'; print qq{before: '$y'}; ;; $y =~ s/^0+//; print qq{after: '$y'}; print $y + 1; " before: '010' after: '10' 11
In fact, because a numeric string is always interpreted as decimal base, it works even without removing leading zeroes.
c:\@Work\Perl\monks>perl -wMstrict -le "my $y = '010'; print qq{before: '$y'}; ;; print $y + 1; " before: '010' 11
But take care, because as soon as the compiler sees the bare 010, it parses it according to the appropriate number base and it stays that way even if stringized immediately thereafter.
c:\@Work\Perl\monks>perl -wMstrict -le "my $y = '' . 010; print qq{before: '$y'}; ;; print $y + 1; " before: '8' 9
Give a man a fish: <%-{-{-{-<
|
|---|