|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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! |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
|||
|
|||
|
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); ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > sorting multi-dimensioned arrays |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|