SPUG: idioms of late
Michael R. Wolf
MichaelRWolf at att.net
Mon Jan 18 23:51:43 PST 2010
On Jan 18, 2010, at 12:04 PM, Fred Morris wrote:
> Lately I've found myself doing a lot of processing of lists... usually
> either listrefs, or a list of keys which can be looked up in a
> hashref.
> I've found myself using a few idioms in place of for/while loops
> repeatedly, and I thought I'd share.
Thanks. It's great to hear success stories and follklore...
> $foo->{names} = [ map { my $x = $_; $x =~ s/\.$//o; $x; }
> @{$foo->{names}}
> ];
Did you try this?
$foo->{names} = [
map {
s/\.$//o;
$_;
} @{$foo->{names}}
];
> The initial "$x = $_;" seems to be necessary.
--
Michael R. Wolf
All mammals learn by playing!
MichaelRWolf at att.net
More information about the spug-list
mailing list