Content deleted Content added
→Hash functions: sarah kong kue Tag: Reverted |
m Reverted edits by 2601:440:C600:D3F0:F080:6922:366D:D246 (talk) to last revision by Jarble: nonconstructive edits |
||
Line 212:
===Hash functions===
There are a few functions that operate on entire hashes. The ''keys'' function takes a hash and returns the list of its keys. Similarly, the ''values'' function returns a hash's values. Note that the keys and values are returned in a consistent but arbitrary order.
<syntaxhighlight lang="perl">
# Every call to each returns the next key/value pair.
# All values will be eventually returned, but their order
# cannot be predicted.
while (($name, $address) = each %addressbook) {
print "$name lives at $address\n";
}
# Similar to the above, but sorted alphabetically
foreach my $next_name (sort keys %addressbook) {
print "$next_name lives at $addressbook{$next_name}\n";
}
</syntaxhighlight>
==Control structures==
|