in reply to Re: define a hash-value, using hash-ref and a list of keys
in thread define a hash-value, using hash-ref and a list of keys

> $cf{$k1}{$k2}{$k3}{"hlst"} //= "";

IMHO the best solution in this case where autovivification is wanted.

For completeness if the perl version is to old for defined-or, one could use a ref to the hash value.

$ perl use Data::Dumper; my $hash; my $rval = \ $hash{a}{b}{c}{"hlst"}; $$rval = "" unless defined $$rval; print Dumper \%hash; __END__ $VAR1 = { 'a' => { 'b' => { 'c' => { 'hlst' => '' } } } };

or you can define an defined-or-assign function to do so

use Data::Dumper; my $hash; defor( $hash{a}{b}{c}{"hlst"} , ""); print Dumper \%hash; sub defor { $_[0] = $_[1] unless defined $_[0]; } __END__ $VAR1 = { 'a' => { 'b' => { 'c' => { 'hlst' => '' } } } };

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)