Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 20th, 2001, 12:56 PM
unobserved unobserved is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 11 unobserved User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to unobserved
Well like the subject says, i'm stumped trying to sort an array of hashes.

I've got an array full of references to hashes, and I can't figure out how to sort it.

Any suggestions?

Reply With Quote
  #2  
Old March 21st, 2001, 11:52 AM
rayman rayman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 10 rayman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to rayman
I am a beginner at perl but maybe this helps

print join ('', sort @hashes);

i cant garanty it works but i juse it in one of my scripts to print
so edit it and maybe it work

Reply With Quote
  #3  
Old March 26th, 2001, 06:44 PM
akashani akashani is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 0 akashani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well, you could just sort the array based on the referenced hashes (memory addresses), but that's probably not what you want.

What you have to do is write your own sort routine. For example:

@Info = (
{ fname => "John", lname => "Doe", age => 34 },
{ fname => "Jane", lname => "Dae", age => 32 },
{ fname => "Michael", lname => "Richards", age => 22}
);

# Print out each persons information, sort it by their last name

foreach $user_hash ( sort { $a->{lname} cmp $b->{lname} } @Info) {
print "Name: $user_hash->{fname} $user_hash->{lname}\n";
print "Age: $user_hash->{age}\n";
}


Look up the documents on sort if this doesn't make sense.

Hope this helps.

- Amir

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Sorting Arrays of Hashes??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT