in reply to Re: compare previous and present hash key values
in thread compare previous and present hash key values

I just converted the hash into an array sorted

using:
my @array = map { $result{$_} } sort { $a<=>$b } keys %result;

Since it's now an array, how may i proceed ?

This is the print of the array sorted without keys though:

$VAR1 = [ [ '172193', '19601', '14835', '16718' ], [ '172193', '19601', '14835', '16718' ], [ '172193', '19601', '14835', '16718' ], [ '172193', '19601', '14835', '16718' ], continues....

for now they all look the same but as it progresses there are differences

I don't understand your code well, also the lines of code added to your code confuses.

Replies are listed 'Best First'.
Re^3: compare previous and present hash key values
by LanX (Saint) on Jan 11, 2014 at 16:19 UTC
    OK once again...

    ( 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)