Oh, I see, sorry.
Actually, both jdporter and I got it wrong.
You don't modify $_ like jdporter thought.
You don't modify %_ like I thought.
Wow, that piece of code is so incredibly bad! You modify some random variable based on the current contents of $_. Whether it'll work or not is random. Most of the time, it won't.
for ( [qw(a a b c)], [qw(d e e f)], ) { print(uinq(@$_), "\n"); # Can't coerce array into hash }
for ('a a b c', 'd e e f') { print(uinq(split), "\n"); # Can't use string ("a a b c") as a HASH + ref while "strict refs" in use }
Adding local $_; causes the a specific variable to be used. That alieviates some of the problem, but that variable needs to be localized too. Why not just use %_?
As an expression:
do { local %_; @_{@_}=(); keys %_ }
As a sub:
sub uinq { local %_; @_{@_}=(); keys %_ }
In reply to Re^8: Remove redundency from an array
by ikegami
in thread Remove redundency from an array
by vc_will_do
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |