And List::MoreUtils::uniq can be faster as it tries to load a library to implement its functionality via DynaLoader. If that fails it implements a plain perl way.
In my test (linux, perl 5.8.8 List::MoreUtils 0.21) the original List::MoreUtils::uniq is about 400% faster than my perl implementation.
If I rename the library, so List::MoreUtils must rely on its perl implementation, my solution is about 20% - 25% faster.
I don't want to argue against List::MoreUtils; but now I wonder about these two (perl) solutions:
# presented in perlfaq4 - How can I remove duplicate elements from a l +ist or array? sub my_uniq { my %h; grep { !$h{$_}++ } @_; } # vs. # List::MoreUtils::uniq sub LM_uniq { my %h; map { $h{$_}++ == 0 ? $_ : () } @_; }
I can't recognize an advantage in the usage of map and the ternary operator.
edit: text refinedIn reply to Re^3: Remove Duplicates from Array
by linuxer
in thread Remove Duplicates from Array
by jpk236
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |