Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by tobyink (Canon)
on Feb 03, 2013 at 19:20 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found