in reply to Removing leading zeros

Sorry brother's,
but the following doesn't work like idunno needs it:
perl -e ' $e = 0034; $e+=0;print $e'
Gives us 28 instead of 34 !!!

This only work if we change this to:

perl -e ' $e = "0034"; $e+=0;print $e'
What happens is that the number 0034 is internaly used by perl as an octal number. And octal 034 is Dec: 28 !!!
what can we do ???

Any hints ?

----------------------------------- --the good, the bad and the physi-- -----------------------------------

Replies are listed 'Best First'.
Re: Re: Removing leading zeros
by chipmunk (Parson) on May 15, 2001 at 01:07 UTC
    Octal interpretation only happens for constants. Removing leading zeroes from a constant is trivial; you just use the Delete key on your keyboard.

    Removing leading zeroes from a number held in a variable (presumably what the original poster was asking) is a different question; various solutions have already been provided. In this case, however, suaveant is correct that you don't need to remove the leading zeroes. If you treat the value as a number, Perl is happy to oblige!