Use a hash with the two digit code as key and then add to the hash. (untested)
#!perl -w my %MyHash = (); my @MyWorka = (); open(MYDATAIN,">" . 'datafilenamehere') || die "Unable to open file: $!"; while ( <MYDATAIN> ) { @MyWorka = split(/,/, $_); # # if it can be less than 10 and still want two digits, then might sprintf %02d to keep # everyone at 2 digits. $MyHash{$MyWorka[n]}++; # where n is index which will hold the 2 digit code(ie, # 0,1,2,etc) } foreach my $MyKey (sort {$MyHash{$a} <=> $MyHash{$b}} keys %MyHash) { # sorts in ascending # sequence. If descending # then switch a and b printf "%2d: %5d\n", $MyKey, $MyHash{$MyKey}; } HTH, Wags ;) -----Original Message----- From: Ray Seals [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 02, 2003 13:57 To: Perl Subject: Use a hash or multi dimensional array? DISCLAIMER: I'm new to programming other than a little bit of scripting for cron jobs. I'm parsing a comma delimited file for a specific 2 letter code on each line in the file. Once I find that 2 letter code I want to increment a count value and store it. I've thought about putting it into a 2 dimensional list that would hold the 2 digit code and a count. So every line I process would look for that 2 letter and the count value. If it finds it, read it in along with the count value. Increment the count value. Remove the old count along with the 2 letter code using a pop. Then push the new value and 2 letter to the list. The only reason I keep looking at a hash is because I need to sort the list when I do my reporting. I thought about taking the cheesy way out and use a case/switch setup, but I won't always know what the 2 letter codes will be. -- Ray Seals <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] ********************************************************** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. **************************************************************** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]