Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7764977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:03:53+00:00 2026-06-01T15:03:53+00:00

I have to match two hashtable, but its keys does not match. So i

  • 0

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:03:55+00:00Added an answer on June 1, 2026 at 3:03 pm

    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”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to generate two random numbers var attackRoll = Math.floor((Math.random()*6)+1);
is there a way to group a matching element but not have that match
I have written a bit of code to match two vector of objects that
I was wondering how can I match two digits but which are not the
I have form where people search for a profile match on two values. In
I have two cases to match: either # ... ([0-9]+,[0-9]+) € ... # or #
I have two fields that I'd like to match. (already done the validation functions
I have two LinkedLists, I'd like to move all elements which match some criteria
hi i have to following model class Match(models.Model): Team_one = models.ForeignKey('Team', related_name='Team_one') Team_two =
In Ruby, I want to have a regex match either of two expressions with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.