in reply to creating defined references to arrays of size zero

My interpretation of what you are looking for is :
my %stacks; my $CurrentArrayRef = $Stacks{nonexistant} || []; # Line above CREATES a ref to an empty array if the stack was undefine +d. #It returns a ref to the contents if there were any. push @$CurrentArrayRef, "New Value"; ... more code ... # Now (re)store the contents into the stack $Stacks{nonexistant} = $CurrentArrayRef;

     "Income tax returns are the most imaginative fiction being written today." -- Herman Wouk

Replies are listed 'Best First'.
Re^2: creating defined references to arrays of size zero
by tlm (Prior) on Jul 14, 2005 at 05:41 UTC

    my $CurrentArrayRef = $Stacks{nonexistant} || [];

    Better yet:

    my $CurrentArrayRef = $Stacks{ nonexistant } ||= [];
    This initializes $Stacks{ nonexistant } conditionally, and assigns its value to $CurrentArrayRef, thereby making this line:
    # Now (re)store the contents into the stack $Stacks{nonexistant} = $CurrentArrayRef;
    unnecessary.

    the lowliest monk