please use real
<code> tags and not
<code>
looks like you want the symmetric difference of two character sets
DB<111> @a1=split//,$str1
=> ("A", "B", "C", "D", "E")
DB<112> @a2=split//,$str2
=> ("B", "C", "D", "E", "O")
DB<113> @h2{@a2}=()
DB<114> @h1{@a1}=()
DB<115> delete @h2{@a1}
DB<116> delete @h1{@a2}
DB<117> (keys %h1, keys %h2)
=> ("A", "O")
see Using hashes for set operations... for background.
UPDATE:
seems like nobody mentioned that its a FAQ How do I compute the difference of two arrays? How do I compute the intersection of two arrays?
UPDATE:
Just in case you only want the unique characters in both strings:
DB<137> $h{$_}++ for (split//,$str1),(split//,$str2)
=> ""
DB<138> \%h
=> { A => 1, B => 2, C => 2, D => 2, E => 2, O => 1 }
DB<139> grep {$h{$_}==1} keys %h
=> ("A", "O")
oops basically already shown by Not_a_Number
EDIT: one liner =)
DB<146> grep {$h{$_}==1} map {$h{$_}++;$_} split//,$str1.$str2
=> ("A", "O")
-
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.