No such thing as a small change | |
PerlMonks |
Re: "last expression" quizby Skeeve (Parson) |
on Oct 19, 2005 at 22:19 UTC ( [id://501454]=note: print w/replies, xml ) | Need Help?? |
% 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
In Section
Seekers of Perl Wisdom
|
|