in reply to Re: Populating a Hash: Can someone help me to understand?
in thread Populating a Hash: Can someone help me to understand?
And your code stops too quickly if either the key or the value is false.while (my $key = shift @keys and my $value = shift @values) { $hash{$key} = $value; }
But even adding the defined test as you did doesn't help. Consider @keys = (1, 2, undef, 3, 4);. You'll never get to 3 or 4.while (defined (my $key = shift @keys) and defined(my $value = shift @ +values)) { $hash{$key} = $value; }
What would work is:
while (@keys and @values) { $hash{shift @keys} = shift @values; }
-- Randal L. Schwartz, Perl hacker
|
---|