in reply to Re^2: compare previous and present hash key values
in thread compare previous and present hash key values
( supposing that the numerical order of IDs is not the compare order you want, but that you still need the ID for further evaluation)
do this to keep record of the order of the keys
my %order; while ( my $rec = $data->fetchrow_hashref ) { push @{ $result{ $rec->{"ID"} } }, $rec->{"item"}; push @order, $rec->{ID}; # read order }
and do this to compare the neighboring keys
my $last = $order[0]; # first key for my $cur ( @order[1..$#order] ) { # following key +s compare($last,$cur); $last = $cur; # keep current +as last }
plz note: compare() is a sub you have to provide, you said "this i know how to".
Within compare you can access the values of the hash '%result' with the neighboring keys '$last' and '$cur'.
like
sub compare { my ($previous,$present) = @_; ... }
Cheers Rolf
( addicted to the Perl Programming Language)
|
|---|