Why is $ h1 {nested} not dumped as a hash, but as some kind of weird scalar (1/8)?
Because you store it in a scalar context!
When you do this:
$h1{nested} = %h2;
You store a scalar. Since %h2 is a hash, you are provided with the ol fraction line. According to the Perldoc website
If you evaluate the hash in a scalar context, it returns false if the hash is empty. If there are key / value pairs, it returns true; more precisely, the return value is a string consisting of the number of buckets used and the number of buckets allocated, separated by a slash.
This explains the 1/8 you get.
What you need to do is save the hash as a reference in another hash. As others have pointed out, this should be:
$h1{nested} = \%h2;
The backslash in front of the hash name gives you the memory location in which the hash is stored. You can use curly braces, but I prefer the backslash.
Look at perldoc prelreftut on your computer (or on the webpage I am linked to). This will tell you how to do things like list of lists, hashes or hashes, lists of hashes and list hashes. Just the word o` warning: if you get too complicated, it will be hard to maintain, so once you have fun take a look at the perldoc Perl Orientation Programming Tutorial .
The perldoc command contains a lot of Perl documentation, including the entire Perl function, the Perl modules installed on your system, and even basic information about the Perl language.
source share