On Sun, Mar 17, 2002 at 12:10:43PM -0700, Chris Fedde wrote:
>
> * Directly address style and resource arguments.
>
> * Expunge levity for the humor impaired.
>
> cvs diff -u perlfaq6.pod
> Index: perlfaq6.pod
> ===================================================================
> RCS file: /home/perlcvs/perlfaq/perlfaq6.pod,v
> retrieving revision 1.8
> diff -u -r1.8 perlfaq6.pod
> --- perlfaq6.pod 31 Jan 2002 04:27:55 -0000 1.8
> +++ perlfaq6.pod 17 Mar 2002 18:58:12 -0000
> @@ -634,10 +634,16 @@
>
> =head2 What's wrong with using grep or map in a void context?
>
> -Both grep and map build a return list, regardless of their context.
> -This means you're making Perl go to the trouble of building up a
> -return list that you then just ignore. That's no way to treat a
> -programming language, you insensitive scoundrel!
> +Both grep and map are mechanisms for generating lists. There may
> +not be anything technically wrong with using grep and map in a void
> +context, except that it does not make your intent clear. Grep and
> +map can be useful to help obfuscate code, but if you intent is to
> +write clear, readable and maintainable code then use for.
I'm sorry but that didn't get much better. This one in the original
This means you're making Perl go to the trouble of building up a
return list that you then just ignore.
was spot on. The new added paragraph
Both grep and map are mechanisms for generating lists. There may
not be anything technically wrong with using grep and map in a void
context, except that it does not make your intent clear. Grep and
map can be useful to help obfuscate code, but if you intent is to
write clear, readable and maintainable code then use for.
is just obfuscation by a tempest of words.
This
There is a potential resource problem with current versions of Perl
when using map and grep in void context. Perl pushes the result
list onto a stack. If the return list is large then your program
wastes memory to no good end.
is also too wordy.
I think the best way would just to slightly clarify to original,
something like:
Both grep and map build a return list, regardless of their context.
This means you're making Perl go to the trouble of building up a
return list that you then just ignore. If the list is large,
you waste both time (to construct the list) and space (you throw
away the list). If your intent is to iterate over the list,
iterate over the list: use foreach().
> -programming language, you insensitive scoundrel!
> =head2 How can I match strings with multibyte characters?
>
> --
> Chris Fedde
--
$jhi++; # http://www.iki.fi/jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen