in reply to Re: How to create a 4 dimension hash
in thread How to create a 4 dimension hash

Will this create the keys {$G_ExcepId}{$G_CauseCode} also ? As its an empty hash before this line:
%HoH = () ; $HoH{"$G_Boardno"} = { "$G_ExcepId" => "{$G_CauseCode => value}" };

Replies are listed 'Best First'.
Re^3: How to create a 4 dimension hash
by Corion (Patriarch) on Sep 22, 2008 at 17:33 UTC

    Your code does not do what you think. Look at perldsc and Data::Dumper to dump out the data structure you're creating.

    "{$G_CauseCode => value}"

    is a string, not a hash reference. So your code

    $HoH{"$G_Boardno"} = { "$G_ExcepId" => "{$G_CauseCode => value}" };

    creates at the second level a hash mapping of the value of $G_ExcepId to the string {... => value}

Re^3: How to create a 4 dimension hash
by jettero (Monsignor) on Sep 22, 2008 at 17:32 UTC

    You could definitely say for sure on your own with Data::Dumper. Check it out.

    -Paul

Re^3: How to create a 4 dimension hash
by ikegami (Patriarch) on Sep 22, 2008 at 20:33 UTC

    Will this create the keys {$G_ExcepId}{$G_CauseCode} also ?

    It's not the keys you should be worried about, but the values (the hash refs) at those keys. And yes, those are created. And thus, so are the keys.

    $HoH{"$G_Boardno"}{"$G_ExcepId"}{$G_CauseCode} = "value";

    is short for something like

    $HoH{"$G_Boardno"} //= {}; $HoH{"$G_Boardno"}{"$G_ExcepId"} //= {}; $HoH{"$G_Boardno"}{"$G_ExcepId"}{$G_CauseCode} = "value";

    due to autovivification. When an undefined value is derefenced, the appropriate value is created.

    >perl -wle"my($x,$y); $y=$x->{k}; print $x; HASH(0x225278) >perl -wle"my($x,$y); $y=$x->[0]; print $x; ARRAY(0x225278)
Re^3: How to create a 4 dimension hash
by Andrew Coolman (Hermit) on Sep 22, 2008 at 17:55 UTC
    Yes it will. You will get value by $G_Boardno which is hash from where you get value by $G_ExcepId which is also hash and so on. You can continue like this creating more and more levels until memory runs out.
    It is equal to :
    $HoH->{$G_Boardno}->{$G_ExcepId}->{$G_CauseCode} = "value";

    Regards,
    s++ą  ł˝ ął. Ş ş şą Żľ ľą˛ş ą ŻĽąş.}++y~-~?-{~/s**$_*ee
Re^3: How to create a 4 dimension hash
by hexcoder (Curate) on Sep 22, 2008 at 19:58 UTC