Guest User

Untitled

a guest
Jan 22nd, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #sifting through a list, the keys are non unique and can show up any number of times with corresponding #level; aqua,purple,blue
  2. #The desire is to sift each key to its highest value; aqua > purple > blue.
  3. #I am using a sub like this to handle updating the value in a hash that uses the key value to
  4. #uniquify the data and will then give me the key with it's highest rated level.
  5. #This seemed a pretty efficient way to do it but I'd like input.
  6. #It's perl but really more interested in the algorithm.
  7.  
  8.  
  9. sub sift_value{
  10. my $value_in = shift;
  11. my $value_old = shift;
  12. return $value_in if $value_in =~ /aqua/i;
  13. return $value_in if $value_in =~ /purple/i && $value_old !~ /aqua/i;
  14. return $value_old;
  15. }
Add Comment
Please, Sign In to add comment