Created
June 17, 2011 19:23
-
-
Save alyx/1032104 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Data::Dumper; | |
my %people = ( | |
cody => { | |
friends => ['aaron', 'alyx', 'foo', 'cow'] | |
}, | |
aaron => { | |
friends => ['alyx', 'cody', 'foo', 'bar', 'moo', 'cow'] | |
} | |
); | |
sub find_mutual | |
{ | |
my @person = @_; | |
my @mutual; | |
foreach my $friend (@{ $people{$person[0]}{friends} }) | |
{ | |
if ($friend ~~ @{ $people{$person[1]}{friends} }) | |
{ | |
push @mutual, $friend; | |
} | |
} | |
return @mutual; | |
} | |
my @mutual_friends = find_mutual('cody', 'aaron'); | |
printf("Your mutual friends: %s\n", join(", ", @mutual_friends)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment