Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
"be consistent"
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (16)
As of 2014-04-17 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (455 votes), past polls