Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: "last expression" quiz

by Skeeve (Parson)
on Oct 19, 2005 at 22:19 UTC ( [id://501454]=note: print w/replies, xml ) Need Help??


in reply to "last expression" quiz

% perl -wle 'sub foo { 1 for @_ } print 2 if defined foo()'
foo does nothing. There is no parameter. So undef is returned. So no wonder nothing is printed.

% perl -wle 'sub foo { 1 for @_ } print 2 if defined foo(3)'
The loop is run once. So a defined value is returned.

% perl -wle 'sub foo { 1 for @_ } print 2 if foo(3) == 0'
The value is defined but it's numerical value is zeroundef == 0

% perl -wle 'sub foo { 1 for @_ } print 2 if foo(3) eq ""'
and it's an empty stringundef eq ""

I think 1 is different from 43 (or 42 or 2 or whatever other number you can come up besides 0) because it's usually used to represent "true".

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-16 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found