I think that roboticus has the ticket with the "uniq" function for question #1. List::MoreUtils is an XS module and should run very fast.

As a thought for question #2, here is some Perl 5.10 code using the smart match operator (~~).

#!/usr/bin/perl -w use strict; use 5.10.0; my @a = qw(alpha beta gamma zulu); my @b = qw(delta alpha kappa gamma beta); my @c = grep{!($_ ~~ @a)}@b; print "@c"; #prints: delta kappa # @c is @b after removing any element # that was contained in @a
This is my first program with this new Perl 5.10 "~~" operator and I have no idea of how "smart" or not "smart" this new operator really is, especially in a loop like above. I would have to run some benchmarks, but since this is one line of code, I leave that to the OP to experiment with and present this as just an idea.

In reply to Re: Merge arrays - seeking slicker approach by Marshall
in thread Merge arrays - seeking slicker approach by puterboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.