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

Re: Efficient Comparison of Array elements

by davorg (Chancellor)
on Jan 08, 2003 at 15:54 UTC ( [id://225280]=note: print w/replies, xml ) Need Help??


in reply to Efficient Comparison of Array elements

You want the intersection and the difference of two sets.

This is in the FAQ.

How do I compute the difference of two arrays? How do I compute the intersection of two arrays?.

By the way, your syntax for creating your arrays:

my @one = [1,2,3,4]; my @two = [2,4,6,8];

is wrong. It should be either:

my @one = (1,2,3,4); my @two = (2,4,6,8);

or

my $one = [1,2,3,4]; my $two = [2,4,6,8];
--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re: Re: Efficient Comparison of Array elements
by aging acolyte (Pilgrim) on Jan 08, 2003 at 16:29 UTC
    davorg

    Thanks a lot, that is roughly what I want. But a couple of follow ups:

    Is this efficient/practical if both arrays get to sizes of 10K elements?

    The array generated for difference contains elements from both arrays. I wanted those unique to @one AND those unique to @two. Again I can do this by comparing @difference with @one and @difference with @two. But I am running the same code three times. Is it practical?

    A.A.

    BTW - as for the syntax thing - a good general rule for SOPW would be "first engage brain then type...."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2025-06-18 21:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.