in reply to Re: require problems
in thread require problems

Well, not really *that* criminal --

it's a non-empty list...

<INCORRECT>
lists in scalar/boolean context return the number of their elements.
</INCORRECT>;

Update: I humbly acknowledge the folly of the above statement.

Should be:

list assignment returns the number of elements.

End Update

Thus:

perl -e '$val = () = 0; print $val';

prints 1 -- true!

Replies are listed 'Best First'.
NEVER a list in a scalar context -- PLEASE!
by merlyn (Sage) on Sep 19, 2000 at 22:24 UTC
    lists in scalar/boolean context return the number of their elements.
    Oh. Once again, trying to dispel the myth of that statement. Repeat after me:
    • You can never have a list in a scalar context...
    • You can never have a list in a scalar context...
    • You can never have a list in a scalar context...
    Now, what's really happening is that you have a list assignment operator in a scalar context, which is defined as having a return value of the number of elements copied across, while giving a list context to the right side.

    In this case, the right side is a simple expression, which gets turned into a list of one element. So we get a "1" for the return value.

    Once more, just so you remember:

    • You can never have a list in a scalar context...

    -- Randal L. Schwartz, Perl hacker

RE: RE: Re: require problems
by Adam (Vicar) on Sep 19, 2000 at 22:31 UTC
    What these two gurus are trying to say is that there is a HUGE difference between lists and arrays. Please don't confuse them.

    An array in scalar context returns the number of elements therein.

RE: RE: Re: require problems
by japhy (Canon) on Sep 19, 2000 at 22:22 UTC
    No, that's not true. Lists do not exist in scalar or boolean context.
    $a = (3,2,1); print $a; # 1
    Read my article ("List is a Four-Letter Word") at my web site for stuff I'd rather not rewrite here.
    perl -e '$val = () = (10,20,30); print $val'
    prints 3.

    $_="goto+F.print+chop;\n=yhpaj";F1:eval