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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:40:12+00:00 2026-06-04T17:40:12+00:00

How come I never see examples like these where you declare the hash, and

  • 0

How come I never see examples like these where you declare the hash, and then put then inside another hash?

my %hash1={};
$hash1{'key1'}='1-111';
$hash1{'key2'}='1-222';
$hash1{'key3'}='1-333';
my %hash2={};
$hash2{'key1'}='2-111';
$hash2{'key2'}='2-222';
$hash2{'key3'}='2-333';

my %main_hash1={%hash1, %hash2};

I’ve only seen examples like these where they put the hashes inside the hash, instead of a variable for the hash:

my %main_hash2=( 'hash1' => {
                            'key1' => '1-111',
                            'key2' => '1-222',
                            'key3' => '1-333'
                    },
             'hash2' => {
                            'key1' => '2-111',
                            'key2' => '2-222',
                            'key3' => '2-333'
                    }
);

(similar with arrays also)

  • 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-04T17:40:13+00:00Added an answer on June 4, 2026 at 5:40 pm

    You can’t store a hash in a hash, you can store a hashref in a hash though:

    my %main_hash1 = ( hash1 => \%hash1, hash2 => \%hash2 );
    

    The same goes with arrays:

    my @main_array1 = ( \@array1, \@array2 );
    

    And with mixes:

    my @array_of_hrefs = ( \%hash1, \%hash2 );
    my %hash_of_arefs = ( arr1 => \@arr1, arr2 => \@arr2 );
    

    This is done all the time; I don’t know why you haven’t seen it and I doubt anyone on SO would know that answer.

    Also, this does not initialize a hash:

    my %hash1={}; ## should be my %hash1; or my %hash1 = ();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've never come across this extension before. It's being used for a front-end interface
I've never come across this before: I have a series of text boxes. The
I have seen many souce codes but I have never ever come across a
I come from the iPhone development world but have never developed desktop applications. Now
Come across what looks at first sight like an MT-issue, but I'm trying to
I'm hoping someone can help me see the real value in these tests because
I come up against this all the time, and I'm never sure which way
Fonts are like a coin lost in the forrest: You're never sure where to
I really come from the world of Http and never did much with the
I always had this silly doubt in mind but never had come up 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.