hmbscully has asked for the wisdom of the Perl Monks concerning the following question:
I have file containing information about different locations. The location names are the unique values. Some cities will have more than one location.
How do I sort the data by city and then by name and still return all the names?
Right now I have the following code:
while($line = <DATA>){ chomp $line; ($junk,$o_country,$o_province,$o_tcenter,$o_addr +ess,$o_city,$o_stprov,$o_mailcountry,$o_postalcode,$o_firstname,$o_la +stname,$o_title,$o_phone,$o_fax,$o_date) = split(/\|/,$line); #the hashes are filled using the test center as the key $testcenters{$o_city} = $o_tcenter; $centercity{$o_tcenter} = $o_city; ... (more values stored) @mycenters = sort byString keys %testcenters; #returns list of centerc +ity in alpha order foreach $city(@mycenters){ foreach $center($testcenters{$city}){ print "$testcenters{$city}<BR>"; #print testcenter name ... (print more stuff here) } }
I know that is wrong because if there are duplicate cities, then only one location name is returned and the other is skipped.
I've stared at this off and on for, honestly several years, and I the issue came up again today and I realized it was time to ask and hope it was some just obvious solution.
Original node content and title restored by GrandFather
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to sort a non-unique value within unique values
by Old_Gray_Bear (Bishop) on Sep 13, 2006 at 21:28 UTC | |
|
Re: How to sort a non-unique value within unique values
by tilly (Archbishop) on Sep 14, 2006 at 00:23 UTC | |
|
Re: How to sort a non-unique value within unique values
by duff (Parson) on Sep 14, 2006 at 03:19 UTC | |
by hmbscully (Scribe) on Sep 14, 2006 at 14:54 UTC | |
|
Re: How to sort a non-unique value within unique values
by GrandFather (Saint) on Sep 13, 2006 at 20:41 UTC | |
|
Re: How to sort a non-unique value within unique values
by BrowserUk (Patriarch) on Sep 13, 2006 at 20:34 UTC |