Q:

Reach a hashtable in perl

I have to match two hashtable, but its keys does not match. So i reach each hashtable and match by values. So following code does not works:
sub _findHashElt
{
    my ($this, $hashTarget) = @_;

    my $isFound = 0;
    my $isItemFound = 1;
    my $isHashFound = 0;
    my $result = undef;
    my %hashTable=%{$this->{templates}};
    my %hashTargetHash=%{$hashTarget};
    my %hashSubTable = undef;

    while (    (my ($key, $value) =  each(%hashTable)) 
           and ($isFound          == 0               ))
    {
        $isItemFound = 1;
        $isHashFound = 0;

        ####################################
        # DOES NOT WORK
        %hashSubTable = %{$hashTable{$key}};
        ####################################

        while (    (my ($subKey, $subValue) =  each(%hashTargetHash))
               and ($isItemFound            == 1                    ))
        {
            $isItemFound = 0;
            while (    (my ($subTableKey, $subtableValue) =  each(%hashSubTable)) 
                   and ($isItemFound                      == 0                    ))
            {
                $isHashFound = 1;
                $isItemFound = ($subValue eq $subtableValue) ? 1 : 0;
            }
        }

        if ($isItemFound == 1 && $isHashFound == 1) {
            $isFound = 1;
            $result = $key;
        }
    }

    return $result;
}

And following code works:
sub _findHashElt
{
    my ($this, $hashTarget) = @_;

    my $isFound = 0;
    my $isItemFound = 1;
    my $isHashFound = 0;
    my $result = undef;

    my %hashTable=%{$this->{templates}};
    my %hashTargetHash=%{$hashTarget};
    my %hashSubTable = undef;

    while (    (my ($key, $value) =  each(%hashTable)) 
           and ($isFound          == 0               ))
    {
        $isItemFound = 1;
        $isHashFound = 0;

        while (    (my ($subKey, $subValue) =  each(%hashTargetHash))
               and ($isItemFound            == 1                    ))
        {
            ####################################
            # WORK
            %hashSubTable = %{$hashTable{$key}};
            ####################################

            $isItemFound = 0;

            while (    (my ($subTableKey, $subtableValue) =  each(%hashSubTable)) 
                   and ($isItemFound                      == 0                    ))
            {
                $isHashFound = 1;

                $isItemFound = ($subValue eq $subtableValue) ? 1 : 0;
            }
        }

        if ($isItemFound == 1 && $isHashFound == 1) {
            $isFound = 1;
            $result = $key;
        }
    }

    return $result;
}

Please someone can tell me, what is the problem please ?
EDIT
#############################################
################# TEST PART #################
#############################################
my $this = {"templates" => {}};
my $example = {'key0' => {'key00' => 'test00', 'key01' => 'test01', 'key02' => '0', 'key03' => 'test03'},
               'key1' => {'key00' => 'test10', 'key01' => 'test11', 'key02' => '1', 'key03' => 'test13'},
               'key2' => {'key00' => 'test20', 'key01' => 'test21', 'key02' => '1', 'key03' => 'test23'},
               'key3' => {'key00' => 'test30', 'key01' => 'test31', 'key02' => '0', 'key03' => 'test33'}};
my $expected = {'key00' => 'test00', 'key01' => 'test01', 'key02' => '0', 'key03' => 'test03'};
$this->{templates}=$example;
_findHashElt($this, \%expected );

In the first case, the key has not been found, and in the second the key has been found ...
EDIT
First case:
$ perl myTest.pl
Key not found

Second case:
$ perl myTest.pl
Key found
{
   key01 : test01
   key00 : test00
   key03 : test03
   key02 : 0
}

EDIT
Another thing, i think it will be usefull
$ perl --version

This is perl, v5.10.1 (*) built for i686-cygwin-thread-multi-64int
(with 13 registered patches, see perl -V for more detail)

A:

Ok, i found the answer at my own question

Extract from perlfunc(1) :
There is a single iterator for  each hash, shared by all "each",
  "keys", and "values" function  calls in the program; it can  be reset
  by reading all the elements from the hash,  or by evaluating "keys
  HASH" or "values HASH".

