G'day emdub,

Welcome to the monastery.

The following code shows how you could handle multiple pairs of strings. I've hard-coded a space to match your "Output". You haven't indicated exactly what you mean by "letter": I've used any character matching /\p{Alpha}/ (see "perluniprops: Properties accessible through \p{} and \P{}") — your concept of "letter" may differ.

#!/usr/bin/env perl -l use strict; use warnings; my @pairs = (['CHARLIE ROOT', 'HARRY NODE'], ['abc1', 'cde1']); print get_non_shared(reverse @$_), ' ', get_non_shared(@$_) for @pairs +; sub get_non_shared { my ($ref, $src) = @_; my %ref_char = map { $_ => 1 } grep { /\p{Alpha}/ } split '' => $r +ef; join '' => grep { ! $ref_char{$_} } split '' => $src; }

Output:

CLI T Y ND ab1 de1

Note that you haven't indicated how you get your pairs of strings nor what combinations are involved in the operations. Does one string equate to one line from a file? Are you operating on just single pairs from matching lines (i.e. ~300 operations) or all possible combinations (i.e. ~90,000 operations)? Depending on the answers to those — and potentially other questions, such as how often do you plan to run the program — some efficiency optimisations may be useful.

-- Ken


In reply to Re: Mostly Harmless by kcott
in thread Mostly Harmless by emdub

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.