SPUG: Grep syntax

Yitzchak Scott-Thoennes sthoenna at efn.org
Fri Jun 15 12:39:45 PDT 2007

On Fri, June 15, 2007 9:53 am, Michael R. Wolf wrote:
> You mentioned the 'x' operator with a scalar LHS.
> With a list LHS, it behaves like the Python idiom you mentioned...
> my @bcopy = (255) x @b;

Saying it that way ("With a list LHS") makes it sound like a violation
of two rules:

First, that operators provide context to their operands, not vice versa.
The operator is what decides if what's on it's left is a list or a scalar.
(For instance, my @bcopy = @b x 1; sets @bcopy to contain a single element
whose value is the number of elements in @b, not a copy of all the elements
in @b.)

Second, related to the first, parentheses don't make a list.  $x = (255)
is no different than $x = 255.

Since IMO it really helps to drive these rules deeply into learner's
brains, my preferred explanation is that ()x is a different op than
plain x, one that provides list context to it's right operand.
()= vs. = I also think of as two different ops.

Unfortunately, over my protests, in 5.8.8, they made qw before x
work as if it had parenthesis around it, so there's that glaring
exception.  Though = has a similar exception when it's left operand
is an array or hash.

More information about the spug-list mailing list