Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Add Comment
Please, Sign In to add comment