|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
I'm having trouble with sorting an associative array by certain parts of it's value. The array's keys are numbers starting at one and going up to whatever the amount of read results is. The values are a number of different things describing a part. The value needs to be parsed to get each particular variable. I want the user to be able to select part# or cost(or any other variable) and have it sort the results by that. Right now I'm breaking it down by putting the key into a new array with it's new value being what the user chose to sort it by. Because associative arrays don't stay sorted I am putting what should be the keys of the sorted values into a new array(maybe I just have too many arrays) (: This array is then used as the keys to the original array to output all the results in the sorted order.
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> foreach $part (keys(%results)) { ($invdate,$invnum,$vendor,$lspartnum,$parttype,$manufname,$modelnum, $serialnum,$desc,$cost,$price) = split(/:/, $results{$part}); if ($sortby eq "pnum") { $sortingresults{$part} = $lspartnum; } if ($sortby eq "cost") { $sortingresults{$part} = $cost; } #etc. } for (sort {$a <=> $b;} (values (%sortingresults))) { @resultsarray = (keys (%sortingresults)); } foreach $part (@resultsarray) { ($invdate,$invnum,$vendor,$lspartnum,$parttype,$manufname,$modelnum, $serialnum,$desc,$cost,$price) = split(/:/, $results{$part}); &DisplayTable; } [/code] I'm sure I'm doing something terribly wrong, or backwards, I can get the output, but it's not in a sorted order. Maybe I'm making it to complicated? Any suggestions would be greatly appreciated. Thanks in advance. [This message has been edited by Obsidian11 (edited August 07, 2000).] |
|
#2
|
|||
|
|||
|
Eeek, that's a big thing you're trying to accomplish here. I'd just use an SQL (mysql) server and have it do all the sorting.
I'm sure what you're trying to do can be done, but I can't think of a quick solution off the top of my head. |
|
#3
|
|||
|
|||
|
Start here -> http://www.devshed.com/Talk/Forums/Forum6/HTML/000278.html
|
|
#4
|
|||
|
|||
|
freeebsd is just an archive of links to old threads
. |
|
#5
|
|||
|
|||
|
Hahaha, yes I've noticed (:
Thank you both for you help, I'll take a look at the old thread and see if it will help me! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Trouble with sorting |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|