in reply to compare previous and present hash key values

Hash keys are not ordered. What do you mean by "first 2 keys"?
my @keys = sort your_sorting_routine keys %result; for my $i (0 .. $#keys - 1) { compare($result{ $keys[$i] }, $result{ $keys[$i + 1] }); }

Or, if you do not want to store the keys in an array, but retrieve them one by one:

my $previous = retrieve_key(); while (defined (my $next = retrieve_key())) { compare($result{$previous}, $result{$next}); $previous = $next; }
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: compare previous and present hash key values
by undisputed (Initiate) on Jan 11, 2014 at 15:26 UTC

    It's neighboring keys actually. So to begin, i will start with the first key in the hash and compare with the second, then the second with the third etc. I tried your code but it says undefined subroutine retrieve_key.

    Best regards.
      Yes, you have to write your_sorting_routine or retrieve_key yourself. In Perl, there is no "neighbouring" hash key - hash keys have no defined order, as has been already pointed out.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Does using array make my life any easier ? please see my last response to user "Rolf"