i have a String that contains a Hash Reference, for example:
my $string = "HASH(0x5602d43a7648)";
How can i access the hash from this reference and print out it's values and keys?
i have a String that contains a Hash Reference, for example:
my $string = "HASH(0x5602d43a7648)";
How can i access the hash from this reference and print out it's values and keys?
You can't, it's too late.
If the variable contains a reference, you can dereference it, though:
my $hash_ref = { a => 42 };
my %hash = %{ $hash_ref };
but once you stringify it, there's no way:
my $string = "$hash_ref";
To create a hash within a hash, or a "Hash of Hashes (HoH)", use the references, not strings:
my %hash = ( key1 => { subkey1 => 'val1',
subkey2 => 'val2' },
key2 => { subkey3 => 'val3' } );
print $hash{key1}{subkey2}, "\n"; # val2