For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2008 > Re: What counts as a "void context" in "Don't use grep in a void conte









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: What counts as a "void context" in "Don't use grep in a void conte
Jenda Krynicky

2008-03-27, 7:12 pm

On Wed, Mar 26, 2008 at 9:47 PM, Rob Dixon <rob.dixon@gmx.com> wrote:
> Jay Savage wrote:
>
> 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
===== Jenda@Krynicky.cz === 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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com