Skip to content

Instantly share code, notes, and snippets.

@andrewsolomon
Created May 21, 2017 17:32
Show Gist options
  • Save andrewsolomon/ddc63eb75a4436cfc7f0b899325e6da1 to your computer and use it in GitHub Desktop.
Save andrewsolomon/ddc63eb75a4436cfc7f0b899325e6da1 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dump 'pp';
use feature 'say';
sub get_max_value_key {
my %hash_args = @_;
# order the keys by their values from greatest to least
my @ranked_keys = sort { $hash_args{$b} <=> $hash_args{$a} } keys(%hash_args);
return $ranked_keys[0];
}
my %exam_marks = (anna => 85, bob => 96, chloe => 78, dave => 64);
say 'Highest mark awarded to '.get_max_value_key(%exam_marks);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment