SPUG: Grep syntax

Michael R. Wolf MichaelRWolf at att.net
Fri Jun 15 09:53:42 PDT 2007


> my @bcopy = @b;
> grep { $_ = 255 } @bcopy

'Ugh....  ' x 10

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;

Depending on the audience, I may write it like this:
    my $b_length = @b;
    my @bcopy = (255) x $b_length;

Oh yeah, and come up with a better name for @bcopy.

> # Create array bcopy containing all 255
> bcopy = [255] * len(b)




More information about the spug-list mailing list