Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: compare two strings and return only he unique values.

by AnomalousMonk (Canon)
on Feb 04, 2013 at 01:57 UTC ( #1016886=note: print w/replies, xml ) Need Help??

in reply to compare two strings and return only he unique values.

Here's a substution-based version that may be somewhat along the lines Learnlot1 was thinking of originally. It does not generalize well to handling more than two strings as the split-to-hash approaches do. It suffers from the vagueness of the implied specification as other approaches do. But it works (for some definition of 'works').

>perl -wMstrict -le "for my $ar_vector ( [ qw(ABCDE BCDEO) ], [ qw(ABCDE BBBBB) ], [ qw(ABCDEA BCDEO) ], ) { my ($s1, $s2) = @$ar_vector; printf qq{'$s1' '$s2' -> '%s' \n}, non_common($s1, $s2); } ;; sub non_common { my ($sa, $sb) = @_; ;; (my $a_sans_b = $sa) =~ s{ [\Q$sb\E]+ }{}xmsg; (my $b_sans_a = $sb) =~ s{ [\Q$sa\E]+ }{}xmsg; return $a_sans_b . $b_sans_a; } " 'ABCDE' 'BCDEO' -> 'AO' 'ABCDE' 'BBBBB' -> 'ACDE' 'ABCDEA' 'BCDEO' -> 'AAO'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016886]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2016-10-28 19:09 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (386 votes). Check out past polls.