programming-examples/perl/Hash/Reverse a hash- use key as the value, and value as the key.pl

9 lines
188 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
$hash{fruit} = apple;
$hash{sandwich} = hamburger;
$hash{drink} = bubbly;
%reversed = reverse %hash;
foreach $key (sort keys %reversed) {
print "$key => $reversed{$key}\n";
}