Skip to content

Instantly share code, notes, and snippets.

@AriT93
Created September 13, 2011 14:20
Show Gist options
  • Save AriT93/1213913 to your computer and use it in GitHub Desktop.
Save AriT93/1213913 to your computer and use it in GitHub Desktop.
Looking for a way to better do this
#sifting through a list, the keys are non unique and can show up any number of times with corresponding #level; aqua,purple,blue
#The desire is to sift each key to its highest value; aqua > purple > blue.
#I am using a sub like this to handle updating the value in a hash that uses the key value to
#uniquify the data and will then give me the key with it's highest rated level.
#This seemed a pretty efficient way to do it but I'd like input.
#It's perl but really more interested in the algorithm.
sub sift_value{
my $value_in = shift;
my $value_old = shift;
return $value_in if $value_in =~ /aqua/i;
return $value_in if $value_in =~ /purple/i && $value_old !~ /aqua/i;
return $value_old;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment