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

  • SEARCH
  • Home
  • 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 8455877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:24:04+00:00 2026-06-10T12:24:04+00:00

i have two array of hashes: AH1 and AH2. $AH1 = [ { ‘id’

  • 0

i have two array of hashes: AH1 and AH2.

$AH1 = [  
          {
            'id' => 123,  
            'name' => abc
          },  
          {
            'id' => 456,  
            'name' => def
          },  
          {
            'id' => 789,  
            'name' => ghi
          },  
          {
            'id' => 101112,  
            'name' => jkl
          },  
          {
            'id' => 1389,  
            'name' => mno
          }  
        ];  

$AH2 = [  
          {
            'id' => 123,  
            'name' => abc
          },  
          {
            'id' => 1389,  
            'name' => mno
          },  
          {
            'id' => 779,  
            'name' => ghi
          }  
        ];  

how can i print hashes of AH1 that are in AH2 using Perl exists Function? or without having to iterate in the array.

  • 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-10T12:24:05+00:00Added an answer on June 10, 2026 at 12:24 pm

    exists locates by index, which are 0,1,2, and not 123,1389,779. exists can’t help.

    Furthermore, you must iterate over both array (one way or another) unless you switch one of the arrays to a hash.

    $HH2 = {
       123 =>  {
                 'id' => 123,  
                 'name' => abc
               },  
       1389 => {
                'id' => 1389,  
                'name' => mno
               },  
       779  => {
                 'id' => 779,  
                 'name' => ghi
               }
    };
    

    In fact, switching is the easiest way to solve this.

    my %HH2 = map { $_->{id} => $_ } @$AH2;
    for (@$AH1) {
        print "$_->{id} in both\n"
           if $HH2{ $_->{id} };
    }
    

    It’s also quite efficient: You iterate over each array only once.

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

Sidebar

Related Questions

I have two array $arr1 = array( 'setting_one' => 'abc', 'setting_two' => 'def', 'setting_three'
I have an array of hashes, each hash has two keys : from and
I have two arrays, each holding arrays with attribute hashes. Array1 => [[{attribute_1 =
I have a sort problem. I have two array int a[] ={index1,index2,index3...indexI}; int b[]
i have two array and i want to make unique array with single array
i have two array the first one is lineChart = [{type : 'line' ,
I have weird behaviour of matplotlib.pyplot. I have two array x and y. I
I have two arrays : array(blue, yellow) and array(blue, green, red, purple) . Is
I have two arrays: Array ( [0] => Array ( [id] => 1 [type]
I have and array with two values and I want to use it 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.