http://www.perlmonks.org?node_id=1016856


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

Yet another (short) way:

my ( $str1, $str2 ) = ( 'ABCDE', 'BCDEO' ); my %count; $count{$_}++ for split //, $str1.$str2; print grep $count{$_} == 1, keys %count;

Replies are listed 'Best First'.
Re^2: compare two strings and return only he unique values.
by Kenosis (Priest) on Feb 03, 2013 at 21:17 UTC

    Won't show "A" when:

    my ( $str1, $str2 ) = ( 'ABCDEA', 'BCDEO' );

      Yeah, I know. But the OP said:

      I am trying to display unique values from two strings

      So is 'A', in your dataset, unique or not?

      Depends upon a better spec, I suppose...

      Update: smls (below) already pointed this out;

        Your solution is elegant and works beautifully with "ABCDE", "BCDEO" -- the OP's two initial strings. But the OP later included "ABCDE", "BBBBB" as options, clearly indicating the possibility of character reptition. Quite agree that a clearer spec would help...