in reply to undef var
The first is being evaluated in a list context, because print takes a list, but the second is evaluted in a scalar context because you're concatenating this. In a scalar context, a list evaluates to the number of elements it contains.
If you change the contexts in your examples, you'll get the opposite results:
The first explicitly asks for a scalar context, and prints 1. The second stays in print's list context and so prints nothing (well, just return=).perl -e 'print scalar(my ($rec) = undef);' perl -e 'print "return=",(my ($rec) = undef);'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: undef var ("list in scalar context")
by tye (Sage) on Jul 03, 2003 at 21:03 UTC | |
by tcf22 (Priest) on Jul 04, 2003 at 17:06 UTC |