Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: padding/substr quirk

by Zed_Lopez (Chaplain)
on Jan 10, 2004 at 21:51 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found