Your first approach is almost there, except that you're looking through the wrong list, repeatedly, which is what drives up your runtime. Basically, what you want is called the "symmetric difference" between two lists, and perlfaq4 (or perldoc -q difference) tells you the common approach.

All that's left for you to do is to canonicalize the names to a common form. For example in your case, abc_12342_tick could be a good common form from which both forms can be derived.

The code in perlfaq4 is:

@union = @intersection = @difference = (); %count = (); foreach $element (@array1, @array2) { $count{$element}++ } foreach $element (keys %count) { push @union, $element; push @{ $count{$element} > 1 ? \@intersection : \@differen +ce }, $element; }

Personally, I like to know whether an element is only in the left or only in the right side of the comparison, so I usually use code like this:

@union = @intersection = @left = @right = (); %count = (); my %left; @left{ @array1 } = 1 x @array; my %common; foreach $element (@array2) { if (exists $left{ $element }) { $common{ $element } = delete $left{ $element }; } else { $right{ $element } = 1; }; }; print "Keys only on the left side:\n"; for (keys %left) { print "$_\n"; }; print "Keys only on the right side:\n"; for (keys %right) { print "$_\n"; }; print "Keys found on both sides:\n"; for (keys %common) { print "$_\n"; };

This only works if you don't have duplicates - the code for handling multiple keys isn't difficult but larger and detracts from the main logic.


In reply to Re: File pairing from different directories by Corion
in thread File pairing from different directories by Zoop

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.