in reply to Re: Hash slice again
in thread Hash slice again
the above code printsuse strict; use warnings; use Data::Dumper; my @a = qw/a b c d/; my @b = qw/a b c d/; my %a; print '--- my @a before ---',"\n", Dumper \@a; undef @a[1,2]; print '--- my @a after ---',"\n", Dumper \@a; print '--- my %a before ---',"\n", Dumper \%a; undef @a{@b}; print '--- my %a after ---',"\n", Dumper \%a;
--- my @a before --- $VAR1 = [ 'a', 'b', 'c', 'd' ]; --- my @a after --- $VAR1 = [ 'a', 'b', undef, 'd' ]; --- my %a before --- $VAR1 = {}; --- my %a after --- $VAR1 = { 'c' => undef, 'a' => undef, 'b' => undef, 'd' => undef };
if @a = (1,2,3), then undef @a[1,2] is proper, undefines $a[2] just undef @b[2], is giving me @b's 0 ,1 and 2 indexes to be undef. if %hash = qw(a b c d) then undef @hash{qw(a c)} is proper, undefines + only $hash{c} just undef @hash1{qw(a c}} is giving me the values of the keys a and c + to be undef
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Hash slice again
by jethro (Monsignor) on Jan 27, 2009 at 15:23 UTC | |
by targetsmart (Curate) on Jan 27, 2009 at 15:48 UTC | |
by ikegami (Patriarch) on Jan 27, 2009 at 16:36 UTC |