programming-examples/perl/Hash/Reverse the hash and use function each to get each pair.pl

15 lines
382 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
%presidents = ( George => "A",
Abe => "B",
Thomas => "C",
Harry => "D" );
@keys = keys( %presidents );
@values = values( %presidents );
print "%presidents with its keys and values reversed\n";
%hash = reverse( %presidents );
while ( ( $key, $value ) = each( %presidents ) ) {
print "$key => $value\n";
}