-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Gerard,
I believe the answer you are looking for is this from `perldoc -f each`: When the hash is entirely read, a null array is returned in list context (which when assigned produces a false (0) value), and "undef" in scalar context. The next call to "each" after that will start iterating again. There is a single iterator for each hash, shared by all "each", "keys", and "values" func tion calls in the program; it can be reset by reading all the elements from the hash, or by evaluating "keys HASH" or "values HASH". Since you have read through the entire hash prior to assigning the new value, it is now returning a null array. By assigning @OU with the contents of the hash, you have reset the hash and can now begin iterating over it again. Steve Gerard Robin wrote: > Hello, > with perl 5.8 with this script: > > #!/usr/bin/perl > #hash2.pl > > use warnings; > use strict; > > my %where=( > London => "England", > Madrid => "Spain", > ); > > print "-"x20, "\n"; > > my ($a, $b) = each %where; > my ($c, $d) = each %where; > > print "$a $b\n"; > print "$c $d\n"; > > print "-"x20, "\n"; > > # my @ou = %where; > > $where{Paris} = "France"; > > while (my ($x, $y) = each %where) { > > print "$x => $y\n"; > } > print "-"x20, "\n"; > > I get the output: > > -------------------- > London England > Madrid Spain > -------------------- > -------------------- > > if I uncomment the line: # my @ou = %where; > > I get: (What I expect) > -------------------- > London England > Madrid Spain > -------------------- > Paris => France > London => England > Madrid => Spain > -------------------- > > Can someone explain to me, why I have to add, my @ou = %where, to get what > I expect? > > tia. - -- =================================================================== Steve Mayer Oracle Corporation Principal Member of Technical Staff Portland Development Center Oracle Collaboration Suite 1211 SW 5th Ave. [EMAIL PROTECTED] Suite 900 Phone: 503-525-3127 Portland, OR 97204 =================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQFC1V+oC4cakfkZLXQRAt9JAJ0ddxytqjSr3r8HILZRw43h0YSIOQCffLZI Jxvp47lalJ45xqCIppVLoC0= =mn7c -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>