in reply to How to create a 4 dimension hash

How about this? :
$HoH{"$G_Boardno"}{"$G_ExcepId"}{$G_CauseCode} = "value";

Regards,
s++ą  ł˝ ął. Ş ş şą Żľ ľą˛ş ą ŻĽąş.}++y~-~?-{~/s**$_*ee

Replies are listed 'Best First'.
Re^2: How to create a 4 dimension hash
by jack_2060 (Initiate) on Sep 22, 2008 at 17:29 UTC
    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}" };

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

      -Paul

      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}

      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)
      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