Hash Sorting Problem
- From: anirban.adhikary@xxxxxxxxx (Anirban Adhikary)
- Date: Mon, 25 Feb 2008 13:30:19 +0530
Dear List
I have written the following code .............
use Data::Dumper;
%file = (14 => "GGG",
11 => "AAA",
101 => "EEE",
1 => "TTT");
print Dumper \%file;
@arr1 = sort { $file{$b} cmp $file{$a} } keys %file; #the oldest entry lies
at the top position
print Dumper \@arr1;
foreach $el(@arr1)
{
delete $file{$el};
print "The $el is removed from the sorted list"."\n";
@arr1 = 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 \@arr1;
}
---------------output ------------
$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.
- Follow-Ups:
- Re: Hash Sorting Problem
- From: John W. Krahn
- Re: Hash Sorting Problem
- Prev by Date: scalar / hash problem in HTML::Parser
- Next by Date: Re: Hash Sorting Problem
- Previous by thread: scalar / hash problem in HTML::Parser
- Next by thread: Re: Hash Sorting Problem
- Index(es):
Relevant Pages
|