Change 21166: Remove the warning in perlfaq about using map in void context :
[email protected] (Rafael Garcia-Suarez)
| Newsgroups | perl.perlfaq.workers,perl.perl5.changes |
|---|---|
| Message-ID | <[email protected]> |
Change 21166 by rgs@rgs-home on 2003/09/10 19:36:30 Remove the warning in perlfaq about using map in void context : From: [email protected] (Abigail) Subject: [PATCH perlfaq6] map in a void context. Date: Tue, 9 Sep 2003 10:31:58 +0200 Message-ID: <[email protected]> Affected files ... ... //depot/perl/pod/perlfaq6.pod#43 edit Differences ... ==== //depot/perl/pod/perlfaq6.pod#43 (text) ==== Index: perl/pod/perlfaq6.pod --- perl/pod/perlfaq6.pod#42~20997~ Tue Sep 2 07:58:21 2003 +++ perl/pod/perlfaq6.pod Wed Sep 10 12:36:30 2003 @@ -679,14 +679,17 @@ hope to know on these matters (a full citation appears in L<perlfaq2>). -=head2 What's wrong with using grep or map in a void context? +=head2 What's wrong with using grep in a void context? -The problem is that both grep and map build a return list, -regardless of the context. This means you're making Perl go -to the trouble of building a list that you then just throw away. -If the list is large, you waste both time and space. If your -intent is to iterate over the list then use a for loop for this +The problem is that grep builds a return list, regardless of the context. +This means you're making Perl go to the trouble of building a list that +you then just throw away. If the list is large, you waste both time and space. +If your intent is to iterate over the list, then use a for loop for this purpose. + +In perls older than 5.8.1, map suffers from this problem as well. +But since 5.8.1, this has been fixed, and map is context aware - in void +context, no lists are constructed. =head2 How can I match strings with multibyte characters? End of Patch.