Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: padding/substr quirk

by Zed_Lopez (Chaplain)
on Jan 10, 2004 at 21:51 UTC ( #320386=note: print w/ replies, xml ) Need Help??

in reply to padding/substr quirk

It doesn't have to do with substr -- it's operator precedence: . and + have equal precedence and left associativity. So "0" . localtime->mon() + 1 is the same as ("0" . localtime->mon()) + 1 -- it performs the concatenation operation first, resulting in "00", which is converted to a number, 0, for the addition, resulting in 1 (for the current month, January).

bash-2.05b$ perl -MTime::localtime -e 'print "0" . localtime->mon() + + 1, "\n"' 1 bash-2.05b$ perl -MTime::localtime -e 'print +("0" . localtime->mon()) + + 1, "\n"' 1 bash-2.05b$ perl -MTime::localtime -e 'print "0" . (localtime->mon() + + 1), "\n"' 01
Comment on Re: padding/substr quirk
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://320386]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2016-04-29 17:46 GMT
Find Nodes?
    Voting Booth?
    :nehw tseb si esrever ni gnitirW

    Results (441 votes). Check out past polls.