in reply to ugly nested if's
my @list1 = get_from_some_place(); my @list2 = get_from_some_other_place(); -------- # Hash method my %lookup_hash; @lookup_hash{@list2} = undef; # This is a hashslice. We don't care abo +ut the values. unless (exists $lookup_hash{$list1[0]}) { # Do something here } -------- # grep method unless (grep { $_ eq $list1[0] } @list2) { # Do something here }
In general, the hash is faster, but takes more memory.
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: ugly nested if's
by Abigail-II (Bishop) on Apr 22, 2004 at 15:25 UTC | |
|
Re(2): ugly nested if's (broken idiom)
by bart (Canon) on Apr 23, 2004 at 09:08 UTC | |
by dragonchild (Archbishop) on Apr 23, 2004 at 11:36 UTC |