Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Note:

The various solutions posted above don't behave exactly the same. This is because the OP hasn't described the problem very precisely, so the commenters (myself included) have made implicit assumptions about the intended meaning of "unique values from two strings".

Interpreting the term "values" in that quote as characters, there are at least two different meanings:

  • Characters that appear exactly once in one of the strings, and don't appear in the other.

    This is what the above solutions by blue_cowdawg and Not_a_Number do.

  • Characters that appear one or more times in one of the strings, and don't appear in the other.

    This is what the above solutions by tobyink and myself do.

If "values" is supposed to mean something other than individual characters, simply adapt any of the above solutions by replacing the split(//, ...) calls with a statement that tokenizes the string into a list of values in the intended way.

In case the strings are not intended to be tokenized in a fixed way, but instead what you are looking for is arbitrary text fragments that appear in one of the strings, but don't appear in that same spot in the other, look into Algorithm::Diff


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-28 20:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found