Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting array of hashes by multiple hash keys

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
0
0
GB
Hi,

I have an array of hashes and need to sort them, I have the following code...
Code:
    # sort
    my @sorted =  sort { $b->{'CompanyName'} <=> $a->{'CompanyName'} } @recs;

Which is fine, but I also want to include within company order, individual name order, as there are mutiple company names for the same company as there are multiple staff.

How would I sort by 'CompanyName' AND 'Surname' ?

Thanks,

1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
It's OK, Worked it out thanks...
Code:
    # sort
    my @sorted =  sort { $a->{'CompanyName'} cmp $b->{'CompanyName'} || $a->{'Surname'} cmp $b->{'Surame'} } @recs;


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top