IBM developerWorks
           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:
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  
Old August 7th, 2000, 12:30 PM
Obsidian11 Obsidian11 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 12 Obsidian11 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 Obsidian11
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).]

Reply With Quote
  #2  
Old August 7th, 2000, 12:50 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 9
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.

Reply With Quote
  #3  
Old August 7th, 2000, 03:14 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Start here -> http://www.devshed.com/Talk/Forums/Forum6/HTML/000278.html

Reply With Quote
  #4  
Old August 7th, 2000, 03:25 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 9
freeebsd is just an archive of links to old threads .

Reply With Quote
  #5  
Old August 7th, 2000, 04:02 PM
Obsidian11 Obsidian11 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 12 Obsidian11 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 Obsidian11
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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Trouble with sorting


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 5 hosted by Hostway