Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Hash Sorting Pr...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 10671 of 11989
Post > Topic >>

Hash Sorting Problem

by anirban.adhikary@[EMAIL PROTECTED] (Anirban Adhikary) Feb 25, 2008 at 01:30 PM

------=_Part_11461_27535052.1203926419402
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Dear List

I have written the following code .............

use Data::Dumper;


%file = (14 => "GGG",
         11 => "AAA",
        101 => "EEE",
          1 => "TTT");


print Dumper \%file;



@[EMAIL PROTECTED]
 = sort { $file{$b} cmp $file{$a} } keys %file; #the oldest entry
lies
at the top position

print Dumper \@[EMAIL PROTECTED]
 $el(@[EMAIL PROTECTED]
)
{

delete $file{$el};
print "The $el is removed from the sorted list"."\n";
@[EMAIL PROTECTED]
 = sort { $file{$b} cmp $file{$a} } keys %file; #the oldest entry
lies
at the top position
print "After sorting the array elements are"."\n";
print Dumper \@[EMAIL PROTECTED]
 ------------

$VAR1 = {
          '1' => 'TTT',
          '11' => 'AAA',
          '101' => 'EEE',
          '14' => 'GGG'
        };
$VAR1 = [
          '1',
          '14',
          '101',
          '11'
        ];
The 1 is removed from the sorted list
After sorting the array elements are
$VAR1 = [
          '14',
          '101',
          '11'
        ];
The 101 is removed from the sorted list
After sorting the array elements are
$VAR1 = [
          '14',
          '11'
        ];

In the last output I think the list is not sorted properly. How can I
solve
this problem.

Thanks&Regards in Advance
Anirban Adhikary.

------=_Part_11461_27535052.1203926419402--
 




 5 Posts in Topic:
Hash Sorting Problem
anirban.adhikary@[EMAIL P  2008-02-25 13:30:19 
Re: Hash Sorting Problem
krahnj@[EMAIL PROTECTED]   2008-02-25 00:21:27 
Re: Hash Sorting Problem
anirban.adhikary@[EMAIL P  2008-02-25 15:02:42 
Re: Hash Sorting Problem
halfcountplus@[EMAIL PROT  2008-02-25 05:24:03 
Re: Hash Sorting Problem
chas.owens@[EMAIL PROTECT  2008-02-25 07:49:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 16:06:22 CDT 2008.