Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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

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 taking refuge in the Monastery: (10)
As of 2016-10-27 15:40 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (366 votes). Check out past polls.