in reply to Re: A list returns its last, an array returns its weight
in thread A list returns its last, an array returns its weight

So lists in scalar context are really just reduced to a list of expressions evaluated with the comma operator e.g
sub with_parens { ('foo', 'bar', 'baz') } # is equivalent to the following in scalar context sub without_parens { 'foo', 'bar', 'baz' } print scalar with_parens(), $/; print scalar without_parens(), $/; __output__ baz baz
Or am I off the mark here?

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Re: A list returns its last, an array returns its weight
by japhy (Canon) on Nov 13, 2002 at 16:26 UTC
    Well, it's that lists don't exist in scalar context.

    In scalar context, a comma-separated group of expressions is a bunch of comma operators doing their thing. In list context, a comma-separated group of expressions is a list.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      In list context, a comma-separated group of expressions is a list.
      ... as long as the CSGoE is surrounded by parens e.g
      my @foo = "one", "two", "three"; my @bar = ("one", "two", "three"); print @foo, $/, @bar, $/; __output__ one onetwothree
      Otherwise it's just a CSGoE :)
      HTH

      _________
      broquaint

      update: ignore me, I'm wrong
      broquaint goes off to study perlop

        The line my @foo = "one", "two", "three"; has three things going on. The first is an assignment to an array (in list context), and the other two are constant strings (in void context).

        "," is an operator. It has a lower precedence than "=". So the expressions "one", "two", "three" aren't in list context.

        _____________________________________________________
        Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
        s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      I thought the contexts were SCALAR and ARRAY. I did not know where was a list context. Oh, hold it, just because the function is called wantarray one cannot assume that is checking for array context. Sigh.

      Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality

        The last sentence of perldoc -f wantarray reads:
        This function should have been named wantlist() instead.

        Abigail