Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello to all, I am another newbie to perl which I am loving...anyways I have been rack my brain trying to find an answer to the problem of a comparing two array's or better yet a list of data from a DB against an array of data. Thanks in advance...

Replies are listed 'Best First'.
Re: list comparisons
by holli (Abbot) on Mar 08, 2005 at 21:51 UTC
    See the "Data: Arrays"-Section in perlfaq4.


    holli, /regexed monk/
Re: list comparisons
by baztastic (Scribe) on Mar 08, 2005 at 22:46 UTC

    I am not sure what type of comparison you are doing, but if you only want to see which data is unique to which list you can use this snippet I originally learned in the Cookbook.

    #...code filling the arrays #@A = DB list #@B = array of data my %seen; # lookup table my @aonly; # info only in list @A my @bonly; # info only in list @B # build lookup table @seen{@B} = ( ); foreach $item (@A) { push(@aonly, $item) unless exists $seen{$item}; } %seen = (); @seen{@A} = ( ); foreach $item (@B) { push(@bonly, $item) unless exists $seen{$item}; } #@aonly = unique to DB list - @A #@bonly = unique to array of data - @B #continue on your merry way...
    -baztastic
      Thanks a mil...that points me in the right direction.
Re: list comparisons
by borisz (Canon) on Mar 08, 2005 at 22:30 UTC
Re: list comparisons
by BazB (Priest) on Mar 08, 2005 at 21:49 UTC
    Array::Compare?

    If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
    That way everyone learns.

Re: list comparisons
by kprasanna_79 (Hermit) on Mar 09, 2005 at 09:49 UTC