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)
You can’t store a hash in a hash, you can store a hashref in a hash though:
The same goes with arrays:
And with mixes:
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: