Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by tobyink (Abbot)
on Feb 03, 2013 at 19:20 UTC ( #1016852=note: print w/ replies, xml ) Need Help??


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

use 5.010; use strict; use warnings; my ($str1, $str2) = ("ABCDE", "BCDEO"); my %in_str1 = map { $_ => 1 } split //, $str1; my %in_str2 = map { $_ => 1 } split //, $str2; my @unique; for my $letter (keys %in_str1, keys %in_str2) { unless ( $in_str1{$letter} and $in_str2{$letter} ) { push @unique, $letter; } } say "Unique letters: @unique";
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name


Comment on Re: compare two strings and return only he unique values.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2014-09-16 23:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (53 votes), past polls