in reply to require problems

If you want evil return values: ( ) = 0;

Try that on for size. It's true. Isn't that criminal? :)

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

Replies are listed 'Best First'.
RE: Re: require problems
by Zarathustra (Beadle) on Sep 19, 2000 at 22:19 UTC

    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!

      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

      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.

      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