in reply to Re^2: Problems with HOHOH modification
in thread Problems with HOHOH modification

$HOHOH{'Alphakey2'}->{'Betakey2'} ||= {}; will initialize with a new (empty) hashref if there's not already an existing key at that level (although keep in mind that that will also populate $HOHOH{'Alphakey2'} with a new hashref as well if it doesn't exist; search for "autovivification" for more details, and go read perlreftut and perlref as well until it becomes clear).

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^4: Problems with HOHOH modification
by tamaguchi (Pilgrim) on Feb 13, 2008 at 19:33 UTC
    $HOHOH{'Alphakey2'}->{'Betakey2'} ||= {}; This was the syntax I was looking for. I havenīt seen this type of syntax before. Thank You. Is it possible to use in on something else? If var is not assigned to assign two to it.. $var||=2;

      Yes!

      || returns the value that dictated the outcome of the operation - either the left hand value if it was true, or the right hand value if the left is false. See perlop and keep in mind that Perl has useful ideas about what constitutes true and false. undef, '', '0' and 0 are all false. Consider:

      print undef || "undef is false", "\n"; print 0 || "0 is false", "\n"; print '' || "'' is false", "\n"; print '0' || "'0' is false", "\n"; print '0xxx' || "'0xxx' is false", "\n"; print 'false' || "'0xxx' is false", "\n"; print '1' || "'0xxx' is false", "\n";

      Prints:

      undef is false 0 is false '' is false '0' is false 0xxx false 1

      Perl is environmentally friendly - it saves trees