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 6708525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:46:12+00:00 2026-05-26T07:46:12+00:00

I am creating a hash of hashes and trying to search or do pattern

  • 0

I am creating a hash of hashes and trying to search or do pattern matching.

Hash is

$hash{$var1}{$var2}{$var3}=$value; #where $var1 =1_1 : $var2 =2_1; $var3 =3,4; 

and i am trying to do a pattern matching with key var3
here $var4 can change values

for (sort keys %{$hash{'1'}{$var4}}) { # var4=2_1 : can also be 2_2 and so on 
    if ($_ =~ m/3,.*/) {  # here 
        $new = $_;        # here new should get the value 3,4
    }
}      

The problem I am stuck with is that unless I do the following

for (sort keys %{$hash{'1'}{'2'}})

I cannot sort the keys ; In short cannot replace 2 with a variable.

  • 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-05-26T07:46:13+00:00Added an answer on May 26, 2026 at 7:46 am

    Have you tried using a nested loop? You’ll need something like this: sort the $var4 keys before going deeper down to access the values you need.

    for my $var4 (sort keys %{$hash{'1'}}) { # var4=2_1 : can also be 2_2 and so on 
        # you can also filter the var4 keys here if you want
    
        for my $var3 (keys %{$hash{1}{$_}}) {
            if ($var3 =~ m/3,.*/) {  # here 
                $new = $var3;        # here new should get the value 3,4
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Each key in a hash has a value that's also a hash. { 100
Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups.
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating a server-side socket will fail if I'm trying to use the same port
I'm creating a Ruby on Rails application, and I'm trying to create/login/logout users. This
I have a hash table generated which I am then trying to add to
I want to create a hash that combines the creating user's user_id + the
I'm creating a hash table in Perl, of an unknown size. The hash table
In Perl, I have a hash of hashes created with a loop similar to
I'm creating a hash that will eventually be dumped on disk in YAML, but

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.