in reply to Re: What does !$saw{$_}++ means
in thread What does !$saw{$_}++ means
With no change to the idiom, I'd write that as,But that extends the lifetime of %saw. If later in the same (or an inner) block, you need to use the same construct, you have to use a different name for the hash, or do a %saw = () - which will then cause errors if you remove the first construct (until you my the newer construct).my %saw; my @out = grep { ! $saw{$_}++ } @in;
I like to write it as:
which doesn't leak the name of the temporary array.my @out = do {my %saw; grep !$saw{$_}++, @in};
|
|---|