Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: two + 2 not equal 4!

by morgon (Deacon)
on Jul 24, 2010 at 02:05 UTC ( #851102=note: print w/ replies, xml ) Need Help??


in reply to two + 2 not equal 4!

If you replace your last line with

printf "two + 2 = %d\n",&two + 2;

(note the ampersand) you get "two + 2 = 4". So it seems the parser treats your "two" as a bareword and converts it to 0 in numeric context (therefore the result).

I wonder why this does not procuce a warning though...


Comment on Re: two + 2 not equal 4!
Download Code
Re^2: two + 2 not equal 4!
by toolic (Chancellor) on Jul 24, 2010 at 02:36 UTC
    So it seems the parser treats your "two" as a bareword and converts it to 0 in numeric context
    No. A bareword would generate a compile error with strict. B::Deparse shows us what's going on.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-11-28 23:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (200 votes), past polls