Hello Jonathan,
Well to start I would suggest you should use a hash if your
$id's are unique. If they aren't then you will have to live with
arrays. To create a hash this is what I would do....
## --- Perl Code Below --- UNTESTED code
my %data; ## A Global declaration
open FILE, "your-file.txt"; ## Insert your comma delimited file here
foreach (<FILE>) { ## Fill read file up til a 'newline'
my @temp = split/,/, $_; ## Split the string
s/^\d{3},//; ## This removes the first 3 digits and
## a comma from $_
$data{$temp[0]} = $_;## Assign a key & a value to your hash
}
## This loop simply prints each key and its value to confirm that
## everything has worked.
foreach (keys %data) {
print "Key:$_ Value: $data{$_}\n";
}
## --- END OF PERL CODE
After the above code is finished you will have a Hash called %data
that contains all data with keys that are created with your ID's. The
next part... actually sorting you can use the code I sent you before.
I am a little confused about one thing though. My code simply sorts
alphabetically or from highest to lowest. From your email I don't
think that's what you are trying to do. However all you ahve to do is
create another hash from %data and then edit the values until they
suit your sorting requirments. For example to sort for only names
that start with 'M' you could do the following:
## --- Perl Code Below --- UNTESTED code
my %sorthash = &SortSub('M',%data);
##---------------------------------------
sub SortSub {
my $letter,%sorthash = @_;
foreach (keys %sorhash) {
my @data = split/,/, $_;
## If it doesn't start with a 'M' then put whatever is needed
## to put it at the end of your sort routine.
$sorthash{$_} = "zzzzzzz" if ($data[0] !~ /^$letter/);
}
}
## END OF PERL CODE
Now you can use the 2 hashes (%data,%sorthash) and use the code I sent
you that sorts alphabetically. Everything that doesn't start with 'M'
with be sent to the end. Let me know if this helps. I don't have a
lot of time these days, but if you are still stuck send me the code
and we'll see if can hack something togther. Cheers
Monday, April 24, 2000, 11:24:58, you wrote:
JS> Cam,
JS> Thanks for the help. I am trying to get the sort part to work. Seems pretty
simple as you stated ... I just need to
JS> figure out HOW to apply it to my program.
JS> My data is stored in a comma delimited file. Here is the format: (with sample
data)
JS> 857,Gabe,Skrinjar,Ravine,109-1,00:60:67:25:91:92,141.195.134.100
JS> 858,Kelly,Murphy,Schultz,313-2,00:60:67:25:91:9b,141.195.134.101
JS> 860,Tara,Dodge,Walker,260-1,00:50:da:c8:ff:7b,141.195.134.102
JS> 861,Fabrizio,Polo,Baldwin,A312-1,00:01:02:28:9f:e6,141.195.134.103
JS> I read in the data:
JS> ($id,$fname,$lname,$build,$room,$adap,$ip) = split(/,/)
JS> and ignore the $id.
JS> A specifc search is done on all the data based on the "subject" of a tab-click on
a TabView object. I have three tabs:
JS> Name, Building, and Adapter Address. For instance: someone wants to get a list of
all the people whose First and last
JS> names begin with 'M'. These are displayed in the ListView window.
JS> The data that is displayed needs to be sorted if the user clicks on a tab.
JS> I guerss I don't know how to store the data in a hash to be used with your code.
Any ideas? I can supply the code if
JS> you want.
JS> Jonathan
JS> --------------------------------------------------------------
JS> Jonathan Southwick [EMAIL PROTECTED]
JS> Technical and Network Services
JS> Allegheny College
JS> Meadville, PA 16335 814-332-2755
--
Best regards,
Cam mailto:[EMAIL PROTECTED]
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com