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 June 15th, 2001, 11:52 AM
Kyuss Kyuss is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 0 Kyuss User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy sorting multi-dimensioned arrays

hi,

I am afraid I am having troubles sorting multi-dimensioned arrays. Extracted and split from a text file, each array element consists of string information except the (primary?) element which has a formatted date eg. 20010615 (year,month,day). I need to order each array in order of date, yet I am having extreme difficulties.

eg
my @arr=(20010615,"string","string");
$values[0]=\@arr;
my @arr=(19991115,"string","string");
$values[1]=\@arr;
my @arr=(20000606,"string","string");
$values[2]=\@arr;


any help much appreciated.

thanks

bren

Reply With Quote
  #2  
Old June 16th, 2001, 07:40 AM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
Thumbs up

Not sure why you would be getting a multiude of arrays from one text file?? but why not push all the arrays together then do a sort of the new array:

Code:
@sorted = (sort {$a <=> $b} @newarray);


Mickalo
__________________

Thunder Rain Internet Publishing

Custom Programming & Database development
Providing Personal/Business
Internet Solutions that work!

Reply With Quote
  #3  
Old June 18th, 2001, 05:10 AM
Kyuss Kyuss is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 0 Kyuss User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
each line of the text file is seperated eg.

1|06 dec 1998|blahblah|blahblah|

so, i split them by |, then i format the date so that it can be ordered: 19981206 and append this to the end of the array so i have

[0] 1 [1] 06 dec 1998 [2] blahblah [3] blahblah [4] 19981206

so i have a whole bunch date similar to this above which i need to be ordered by [4]

i tried

my @sortedvalues = (sort { $allValues[$a]->[4] <=> $allValues[$b]->[4] } @allValues);

and altough i didnt get an error i didnt get a result either...is this totally off track?

Reply With Quote
  #4  
Old June 18th, 2001, 08:31 AM
Kyuss Kyuss is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 0 Kyuss User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
wouldnt you just know it, after having a break from that, i come back and this seems to work:

@sorted = (sort {$a->[11] <=> $b->[11]} @allValues);


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > sorting multi-dimensioned arrays


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