in reply to Re^2: Scalar Vs. List context
in thread Scalar Vs. List context

Expressions that are list elements are no exception. The list operator decides the context of its operands based on its context:

@a = (1,2,3,4); # list, list, list, list
$a = (1,2,3,4); # void, void, void, scalar

Your second example does not have any "list elements" because you can't have a list in scalar context.

Replies are listed 'Best First'.
Re^4: Scalar Vs. List context
by ikegami (Patriarch) on Jul 13, 2009 at 15:17 UTC

    Not so. You're considering different definitions of "list" as equivalent.

    A list value can't be evaluated in scalar context. Or any context. They aren't operators, so they can't be evaluated. They exist on the stack.

    The list operator, on the other hand, can be evaluated in any context. Just like every other operator (as far as I know).

    >perl -MO=Concise -e"@a = (1,2,3,4);" ... - <1> ex-list lKP ->8 <-- "l" for list context ...
    >perl -MO=Concise -e"$a = (1,2,3,4);" ... 5 <@> list sKP ->6 <-- "s" for scalar context ...
    >perl -MO=Concise -e"(1,2,3,4); 1" ... 4 <@> list vKP ->5 <-- "v" for void context ...

    A less ambiguous wording of the statement you made is: An operator can't evaluate to (return) a list in scalar context.

    A list operator can be evaluated in scalar context, but it must evaluate to a scalar in scalar context

Re^4: Scalar Vs. List context
by Anonymous Monk on Jul 12, 2009 at 12:55 UTC
    Often repeated, but what do you call  ( 1 , 2 , 3 , 4 );? :D
      A reply falls below the community's threshold of quality. You may see it by logging in.