@saw{ @arr } = (); # The line I'm not understanding
Others said that this is a hash slice. Yeah, but how, and why?
It's context again. Consider:
{}; # hash reference []; # array reference %hash; # named hash $hash{'foo'} = 'bar'; # left-hand-side (LHS) of '=' in scala +r context @ary = (1,2,3); # LHS & RHS are in list context: # assign a list to an array named ' +ary' $hash{'foo'} = @ary; # LHS context(scalar) forces RHS scala +r context: # $hash{'foo'} == 3 , i.e. scalar(@ +ary) @hash{qw(foo bar quux)} = @ary; # LHS in list context, RHS in list con +text: # $hash{'bar'} == 2; $hash{'quux'} +== 3
The prefixes ($,%,@,&) for identifiers enforce context. So, @hash{@ary} = @list uses the %hash in list context, for which use the (imho) hard to grasp idiom 'slice', for naming the whole LHS expression, has settled.
--shmem
update: replaced "an array slice" with "a hash slice". Of course I meant "hash slice", as per ikegami's comment below. Glitches the like often happen to me, whilst thinking ahead. But best was a friend who reported she once thought "seven", said "1" and wrote "4", all at the same time..
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re: De-Duping An Array
by shmem
in thread De-Duping An Array
by SheridanCat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |