Advertisement
Guest User

Untitled

a guest
May 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.56 KB | None | 0 0
  1. # This function removes the duplicates in @candidates & returns a hash of candidates (%candidates)
  2. # which contains candidates & their number of occurences in @candidates
  3. # This function take as argument the list of candidates (@candidates)
  4. sub clean_candidates {
  5.     my ($this,@candidates) =  @_;
  6.     my %candidates = (); # my %candidates ( $candidate => $nbOcc );
  7.     foreach my $candidate (@candidates){
  8.         $candidates{$candidate} ++;
  9.     }
  10. my %sorted_candidates = sort ({ $candidates{$a} <=> $candidates{$b} } %candidates);
  11.     return %sorted_candidates;
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement