in reply to Re: Autovivification and hash slices
in thread Autovivification and hash slices

Yeah, that is clear :). My problem is the modification of the original hash without touching the hash itself... and it only happens with hash slices :(

Replies are listed 'Best First'.
Re^3: Autovivification and hash slices
by thundergnat (Deacon) on Aug 17, 2011 at 14:20 UTC

    Ah. Sorry, kind of glossed over the "slice" aspect there. All right, try this then.

    use Data::Dumper; sub mydump($) { print Data::Dumper->Dump( [ $_[0] ], ['*hash'] ); } sub myjoin { my ($sep, $href, @keys) = @_; my @exists = grep { exists($href->{$_}) } @keys; return join $sep, @exists; } my %hash = (key1 => 'a'); my $s1 = join( ':', @hash{qw(key)} ); mydump( \%hash ); my $s2 = myjoin( ':', \%hash, qw/key1 key2 key3/ ); mydump( \%hash );