in reply to List Comparison

Howdy!

What sort of efficiency are you looking for? Time? Space? Coding?

Your code will make repeated scans of @a, being O(n**2), but it takes up almost no extra space.

Something like

my %a = map { ($_, 1) } @a; @c = grep $a{$_}, @b;
trades space for time, making a single pass over @a and @b, at the expense of making a hash with the elements of @a as keys. If @a is really big, the memory footprint could become an issue.

Update: I see that you found stuff in CPAN while I was writing this; I was going to hit CPAN and post an update, but...

yours,
Michael

Replies are listed 'Best First'.
Re^2: List Comparison
by ketema (Scribe) on Sep 09, 2004 at 16:06 UTC

    Thanks for replying. yes I did find some stuff on CPAN right after the initial post. Hoenestly this is why I love PERL, everytime I am writing something and I have a idea or wish I could do something easier, I find it! Either here, cpan or some other group. Thanks again for the help, and to answer your question I was looking for code effiency in this instance, and your two lines was better than my 3, so that works. I like the List-Compare Mod, and I also found List-Utils which I am looking through now. we'll see how the scrip goes.


    thanks again