Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a
- 2
- b
- 6
- a
- 4
- f
- 2
- b
- 1
- a
- 7
- %hash = {
- a => 2,
- b => 6,
- a => 4,
- f => 2,
- b => 1,
- a => 7,
- };
- a-->7
- b-->6
- f-->2
- unless (exists $hash{$key} and $hash{$key} >= $value)
- {
- $hash{$key} = $value;
- }
- #Add an element to the array of values for this key.
- push @{ $hash{$key} }, $value;
- use List::Util qw/max/;
- print max @{ $hash{$key} };
- %info;
- # A loop reading two lines.
- while( my $key = <> ) {
- my $value = <>;
- # Handle the case where there are an odd number of lines.
- die "Odd number of lines" unless (defined $value);
- # Assuming only non-negative values, we just silently want to compare
- # keys not seen before as having value 0. See 'perllexwarn' manual page
- no warnings 'uninitialized';
- $info{$key} = $value if $info{$key} <= $value;
- }
- # Dump the result
- say "$_ --> $info{$_} for keys %info;
Add Comment
Please, Sign In to add comment