puterboy:

I don't know of a way to do so, but List::MoreUtils has a handy function uniq to handle the first case:

#!/usr/bin/perl use strict; use warnings; use List::MoreUtils qw(uniq); my @a = qw(alpha beta gamma); my @b = qw(delta kappa gamma); my @c = uniq(@a, @b); print join(", ", @c), "\n";

You'll also find some interesting items in List::Util, Hash::Util and Scalar::Util.

But if you find the temporary a distraction and don't want to include a module for just that purpose, just hide it in a subroutine and go ahead and use the temporary in your subroutine. After all, a temporary isn't necessarily inefficient. So by writing a subroutine with a good name, you can make the code cleaner and self-documenting at the same time, as in the above example. I find that some code can be difficult to read when there's "too much action" happening in a statement, and you may find it difficult to maintain if the statement is too hard to create. So just relax, write a subroutine to do your dirty work, and use it--or include an appropriate module, where someone has already done the dirty work for you!

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Merge arrays - seeking slicker approach by roboticus
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.