Link to home
Start Free TrialLog in
Avatar of Alex Porter
Alex PorterFlag for United States of America

asked on

Consecutive Sorting

I have two consecutive functions that are very similar.  Both have a sort function, but only the first one works.  How can I make the second one sort too?  Also, how could I sort by element rather than by key?

Thanks, Alex



&buildAgeFile;
&buildCountriesFile;

sub buildAgeFile {

     open (PROFILES,"<$ProfileData") or die "can't open $ProfileData $!";
     while( <PROFILES> ){
          $agecount{$this_year - (split/\|/)[9]}++;
     }
     close PROFILES;

     open AGEOUTPUT,">$AgeStats" or die "Can't open $AgeStats $!";

     for( sort {$a<=>$b} keys %agecount ){
          print AGEOUTPUT "$_|$agecount{$_}\n";
     }
}

sub buildCountriesFile {

     open (PROFILES,"<$ProfileData") or die "can't open $ProfileData $!";
     while( <PROFILES> ){
          $countriescount{(split/\|/)[5]}++;
     }
     close PROFILES;

     open COUNTRYOUTPUT,">$CountriesStats" or die "Can't open $CountriesStats $!";

     for( sort {$a<=>$b} keys %countriescount ){
          print COUNTRYOUTPUT "$_|$countriescount{$_}\n";
     }
}
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Alex Porter

ASKER

Thank you.  Worked great, as usual!
Alex