Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by Kenosis (Priest)
on Feb 03, 2013 at 21:24 UTC ( #1016861=note: print w/ replies, xml ) Need Help??


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

Won't show "a" when:

my $string1="abcdefa"; my $string2="defghi";


Comment on Re^2: compare two strings and return only he unique values.
Download Code
Re^3: compare two strings and return only he unique values.
by blue_cowdawg (Monsignor) on Feb 04, 2013 at 15:11 UTC
        Won't show "a" when:

    That's because "a" isn't unique. :)

    printf "%s\n",join(",", keys %een);
    would show "a" and all the other letters once.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

      Your code quite effectively forms a union of the two strings' characters. However, the OP's request was to 1) compare two strings, and 2) return only the unique values. Where does your code compare the two strings? Forming a union of their characters does not compare the two strings. In fact, if we strictly regard their union as a non-multiset of characters, "a" is unique, since (set notation): {a} = {a,a} = {a,a,a}. Thus, "a" should still appear in their union--even with two occurrences within one string.

      As has been point out, the OP's specs are equivocal, yet I tend to favor "unique" as meaning a character (replicated or not) that only belongs to one or the other string (i.e., "unique to")--and is not in both.

            I am trying to display unique values from two strings "ABCDE", "BCDEO" to return "AO"

        was the OP's request. As a matter of fact my code does exactly what they were asking for. Splitting the two strings into single characters and counting the character's occurrence within the string is how I'd approach it.


        Peter L. Berghold -- Unix Professional
        Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2014-09-23 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (224 votes), past polls