in reply to Re: nooby question about @+, @-
in thread nooby question about @+, @-

  1. @_=/./g;: The RHS of a list assignment operator is evaluated in list context.
  2. ()=/./g;: The RHS of a list assignment operator is evaluated in list context.
  3. /./g;: A expression statement followed by another statement is evaluated in void context[1].
  4. (/./g);: A expression statement followed by another statement is evaluated in void context[1].
  5. ()==/./g;: The RHS of a comparison operator is evaluated in scalar context. [Updated]
  6. $_[/./g];: The index expression of an array element is evaluated in scalar context.
  7. /./g;: The statement at the end of a while loop is evaluated in void context.

The behaviour of the match operator in void context doesn't appear to be documented, but is sensibly acts as if it was evaluated in scalar context.

$ perl -E'$_="abc"; /./g; /(.)/g; say $1' b

  1. Not scalar context, as previously mentioned.

Replies are listed 'Best First'.
Re^3: nooby question about @+, @-
by AnomalousMonk (Archbishop) on Oct 28, 2014 at 14:24 UTC
    5.  ()==/./g;: The RHS of a list assignment operator is evaluated in list context.

    Visually tricky, this is actually a pointless comparison evaluating in void/scalar context:

    c:\@Work\Perl>perl -wMstrict -le "$_ = 'abc'; ()== /./g; /(.)/g; print qq{'$1'}; " Useless use of numeric eq (==) in void context at -e line 1. Use of uninitialized value in numeric eq (==) at -e line 1. 'b'

      Oops, fixed.