3 ms·
It's only a surprise if you don't understand it. Every Perl programmer needs to fully grok and embrace it because it's a core language feature. For others, th
by draegtun 13y ago
It's only a surprise if you don't understand it. Every Perl programmer needs to fully grok and embrace it because it's a core language feature.
For others, this is what EdwardDiego is referring to:
my %hash = (a => 1, b => 2, c => 3, d => 4);
# list context (plural)
my @keys = keys %hash;
my ($key1, $key2, @rest_of_keys) = keys %hash;
# scalar context (singular)
my $number_of_keys = keys %hash;
say scalar keys %hash;
# An example of iterator usage
my ($first_key, $first_value) = each %hash;
my ($second_key, $second_value) = each %hash;
# void context
keys %hash; # resets iterator