Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Difference between two arrays - is there a better way?

by JavaFan (Canon)
on Aug 09, 2011 at 09:22 UTC ( #919435=note: print w/replies, xml ) Need Help??


in reply to Difference between two arrays - is there a better way?

Your initial solution relies on users not appearing twice in a list. And that there's no user listed only in the disabled users. I very much prefer the solution of your coworker, which does not rely on these dependencies.

And if you insist on a map/grep solution:

my %disabled = map {($_, 1)} @list2; my @active = grep {!$disabled{$_}} @list1;
This solution doesn't rely on the dependencies mentioned above either.

Replies are listed 'Best First'.
Re^2: Difference between two arrays - is there a better way?
by blindluke (Hermit) on Aug 09, 2011 at 09:36 UTC

    Thanks.

    Both dependencies will always be met in this particular case - as I mentioned, this was not a general problem.

    Still, I also prefer the second solution - it's not only more general than mine, but looks better, and seems more simple/elegant (although the aesthetic argument may not be as valid as the one you mentioned - that it is more general).

    I was simply wondering about other ways, in the spirit of TMTOWTDI. Thank you, and thanks to BrowserUk for both other solutions.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://919435]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2019-10-14 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?