Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comparing lists and getting an exemtion report

by Saadat.123 (Initiate)
on Apr 20, 2012 at 18:35 UTC ( #966232=perlquestion: print w/ replies, xml ) Need Help??
Saadat.123 has asked for the wisdom of the Perl Monks concerning the following question:

Okay I am a typical VBA part-time programmer. Use VBA to solve a few problems. I have been using Perl/Java offtimes to find solutions and automation to a few tasks that I do. Now typically I'd use a database (access) and an SQL statement to get my results but I have been challenged not to use SQL. I have a super list of data (A) and a sublist (B). I need to generate a list (C) that is in (A) but not in (B).... what would be the fastest way in perl?

Comment on comparing lists and getting an exemtion report
Re: comparing lists and getting an exemtion report
by Riales (Hermit) on Apr 20, 2012 at 18:39 UTC

    How big are these lists? If they're not incredibly large, something like this should work:

    # Assuming @list_a and @list_b my %b; $b{$_} = 1 foreach (@list_b); my @list_c; foreach (@list_a) { push @list_c, $_ unless $b{$_}; }
      # Assuming @list_a and @list_b my %b; $b{$_} = 1 foreach (@list_b); my @list_c = grep { not $b{$_} } @list_a;
Re: comparing lists and getting an exemtion report
by Kenosis (Priest) on Apr 20, 2012 at 19:56 UTC

    Although not as nicely readable as Riales's solution, here's another option:

    map{$setB{$_}++}@listB; @listC = grep{!$setB{$_}}@listA;

    Hope this helps!

Re: comparing lists and getting an exemtion report
by Anonymous Monk on Apr 20, 2012 at 21:37 UTC
    I think that we would need to know a great deal more about the exact nature of your problem, and of your data and of where that data now is, in order to answer it meaningfully.
Re: comparing lists and getting an exemtion report
by eyepopslikeamosquito (Canon) on Apr 21, 2012 at 00:37 UTC

    Essentially the same question was asked today in removing a sublist. You might like to check the answers given there and perlfaq4 (arrays section) and Perl Cookbook, recipe 4.8 "Finding elements in one array but not another".

    Re performance, the way to find out is to use the Benchmark module to compare the running times of various solutions.

Re: comparing lists and getting an exemtion report
by BillKSmith (Hermit) on Apr 21, 2012 at 01:41 UTC
    The CPAN module List::Compare sounds perfect. I would certainly include it in any benchmark study of this problem. List::Compare

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://966232]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-04-20 04:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls