Similar Threads:
1.Howto reverse SortByValue with Tie::IxHash
Hi,
I have a problem using Tie::IxHash.
My question is how can I sort the hash
by value in descending order.
I tried this to get the descending order,
but doesn't seem to work:
__BEGIN__
my %hash =(
'1-1' => 3,
'2-3' => 2,
'2-2' => 1,
'1-2' => 6,
'1-3' => 3
);
my $t = Tie::IxHash->new(%hash);
$t->SortByValue; # ascending, ok!
$t->$hash{$b}<=>$hash{$a}SortByValue; #tried this but doesn't work
__END__
Can anybody advice how to go about this?
Thanks beforehand.
Regards,
Edward WIJAYA
SINGAPORE
2.Reverse SortByValue with Tie::IxHash
Hi,
I am a newbie in using Perl Module
especially it's OO method.
I have a problem using Tie::IxHash.
My question is how can I sort the hash
by value in desending order.
e.g:
$t->SortByValue; # ascending
I tried this to get the descending order, but doesn't seem to work:
$t->$hash{$b}<=>$hash{$a}SortByValue;
Please kindly advice, how can I go about it.
This is the hash, by the way:
my %hash =(
'1-1' => 3,
'2-3' => 2,
'2-2' => 1,
'1-2' => 6,
'1-3' => 3
);
Thanks beforehand.
Regards,
Edward WIJAYA
SINGAPORE
3.Using Tie::IxHash order a hash reference
Hi,
How can I order the entries in a hash if I use a reference to a hash
instead of a hash. For e.g.
$ref={
key=>"value",
};
instead of
%ref=(
key=>"value",
);
Thanks!
4.maintaining order in a hash (without Tie::IxHash)
Many times, there exists a module on CPAN that solves a problem I'm
attempting to solve.
I'm aware that generally the better choice to solving such a problem
is to use the CPAN module.
However, regarding the problem of maintaining sort order of a hash,
and the Tie::IxHash module, I have a question.
I've heard that Tie::IxHash can be a little slow, and the cost of
using this in addition to installation costs (where developers don't
have the permission to have modules installed, especially across all
environments, and the process for having the module(s) installed by
admins can be trying to say the least) is much higher than the simple
solution of adding an extra sortval attribute to a hash value, where
the value of sortval is simply an incremented counter.
then if you need to access the hash in the order in which items were
inserted, you could simply:
for my $key ( sort { $hash{$a}{sortval} <=> $hash{$b}{sortval} } keys
%hash ) {
# do something
}
Is there something wrong with my reasoning? Would this solution be a
good candidate for addition into the FAQ How can I make my hash
remember the order I put elements
into it?
5.Different behavior between eval "07" and eval "08"
eval "07" gets 7 but eval "08" gets an undefined value. I tested perl
5.8.8 on fedora 8 and ubuntu.
Is there any difference between those two eval statements? Is this a
bug?
6. Chaining a Tie::File to a Tie::Tk::Listbox
7. tie() with DB_File not tie()ing ?
8. Is Tie::CSV_File dependable on Tie:File