programming-examples/perl/Hash/Reverse the hash and use function each to get each pair.pl
2019-11-15 12:59:38 +01:00

15 lines
382 B
Raku

%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";
}