Alex Porter
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,">$Countries Stats" or die "Can't open $CountriesStats $!";
for( sort {$a<=>$b} keys %countriescount ){
print COUNTRYOUTPUT "$_|$countriescount{$_}\n" ;
}
}
Thanks, Alex
&buildAgeFile;
&buildCountriesFile;
sub buildAgeFile {
open (PROFILES,"<$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")
while( <PROFILES> ){
$countriescount{(split/\|/
}
close PROFILES;
open COUNTRYOUTPUT,">$Countries
for( sort {$a<=>$b} keys %countriescount ){
print COUNTRYOUTPUT "$_|$countriescount{$_}\n"
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Alex