in reply to Module Bloat and the Best Solution
Something nobody else seems to have picked up on yet is your assertion that both examples are 2 lines. It's true, but only until you want to uniquify more than one list!
Compare
my %tmp = map { $_ => 1} @foo; my @uniq_foo = sort keys %tmp; %tmp = map { $_ => 1} @bar; my @uniq_bar = sort keys %tmp; %tmp = map { $_ => 1} @baz; my @uniq_baz = sort keys %tmp;
with
use List::MoreUtils; my @uniq_foo = uniq @foo; my @uniq_bar = uniq @bar; my @uniq_baz = uniq @baz;
Four lines instead of six, and it's getting a lot harder to argue that the two approaches are equally readable.
Yes, you could also define your own uniq function, but why bother when it's been done for you already? If you're worried about people who don't have List::MoreUtils, then just copy the existing uniq function out of that into your own code (license permitting). You'll still be reusing ready-made, ready-tested CPAN code, and that's still usually better than reinventing the wheel.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Module Bloat and the Best Solution
by BrowserUk (Patriarch) on Nov 10, 2007 at 11:49 UTC | |
Re^2: Module Bloat and the Best Solution
by blazar (Canon) on Nov 10, 2007 at 12:42 UTC | |
Re^2: Module Bloat and the Best Solution
by KurtSchwind (Chaplain) on Nov 15, 2007 at 17:39 UTC |