On Wed, Mar 26, 2008 at 9:47 PM, Rob Dixon <[EMAIL PROTECTED]> wrote:
> Jay Savage wrote:
> >
> > If you want to see grep really shine, though, think about ways you
> > might use it to avoid calling print for every element in the return
> > list, e.g.
> >
> > print join "\n", grep {$_ % 2 == 0} @list;
>
> I think that's very misleading. Why should I want to avoid calling print
> for each element? What you've written is the sort of thing for which
> Perl gets a bad name - it's less readable and has no obvious benefits
> over
>
> print "$_\n" foreach grep { $_ % 2 == 0 } @list;
I do not see how is
print join "\n", grep {$_ % 2 == 0} @list;
any less readable than
print "$_\n" foreach grep { $_ % 2 == 0 } @list;
Would perhaps a pair of braces help?
print join( "\n", grep {$_ % 2 == 0} @list);
"I want to PRINT, JOINed by a newline, all even elements from @list"
instead of
"I want to print the item and a newline for each even element from
@list". A big difference.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/