SPUG: Grep syntax
John W. Krahn
krahnj at telus.net
Fri Jun 15 10:09:55 PDT 2007
Bill Campbell wrote:
>
> The author of the perl (Net::CIDR from CPAN) seems to like using grep as a
> method of processing arrays while doing no regular expression checking. He
> also does things like this to create an array, @bcopy, the same size as @b,
> populated with 255. This also takes advantage of perl's ``magic'' where
> looping through an array allows one to modify elements of the array by
> manipulating $_;
>
> my @bcopy = @b;
> grep { $_ = 255 } @bcopy;
Or you could do that like this:
$_ = 255 for my @bcopy = @b;
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
More information about the spug-list
mailing list