[svn:perlfaq] r10394 - perlfaq/trunk

[email protected] Sun, 9 Dec 2007 09:47:16 -0800 (PST)
Newsgroups perl.cvs.perlfaq
Message-ID <[email protected]>
Author: comdog
Date: Sun Dec  9 09:47:15 2007
New Revision: 10394

Modified:
   perlfaq/trunk/perlfaq4.pod

Log:
* perlfaq4: How do I reset an each() operation part-way through?
	+ updated answer to note that keys and values in void
	context will do the trick.


Modified: perlfaq/trunk/perlfaq4.pod
==============================================================================
--- perlfaq/trunk/perlfaq4.pod	(original)
+++ perlfaq/trunk/perlfaq4.pod	Sun Dec  9 09:47:15 2007
@@ -2071,10 +2071,16 @@
 
 =head2 How do I reset an each() operation part-way through?
 
-Using C<keys %hash> in scalar context returns the number of keys in
-the hash I<and> resets the iterator associated with the hash.  You may
-need to do this if you use C<last> to exit a loop early so that when
-you re-enter it, the hash iterator has been reset.
+(contributed by brian d foy)
+
+You can use the C<keys> or C<values> functions to reset C<each>. To
+simply reset the iterator used by C<each> without doing anything else,
+use one of them in void context:
+
+	keys %hash; # resets iterator, nothing else.
+	values %hash; # resets iterator, nothing else.
+
+See the documentation for C<each> in L<perlfunc>.
 
 =head2 How can I get the unique keys from two hashes?