Preceding a number with escape character ‘\’ produces garbage value
Ex:
$a = \12;
print $a;
This code gives below output
SCALAR(0x2001ea8)
and the output changes when I again execute the program.
If I take a value(number) from user when the user gives any input starting with zero, I dont want it to interpret as octal number. So I wanted to escape zero if the number starts with zero.
[In a comment, the OP explained he wants numbers input by the user to be treated as decimal even if they have leading zeroes.]
In numerical literals (code that produces a number), a leading zero tells Perl that the number is in octal.
But that does not apply to numification (converting a string to a number).
So you don’t have to do anything special. A
045input by the user means forty-five (not thirty-seven) if you use it as a number.If for some reason you did need to get rid of the leading zero, you could use
The
(?!\z)makes sure"0"doesn’t become"".