Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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]
[Corion]: ... that can use templates from the HTML (via <script language="text/ template">... my template ...</script> and otherwise gets out of my way. But it seems that is not how the Javascript world is, currently :-/
[Corion]: I guess my question is, has anybody worked with React, Ember, Angular (v2, v4, v.whatever) or any other JS client-side dynamic rendering/virtual DOM thingie and found a simple, single-file solution like jQuery?

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2017-03-27 19:05 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (321 votes). Check out past polls.