Skip to content

Instantly share code, notes, and snippets.

@alyx
Created June 17, 2011 19:23
Show Gist options
  • Save alyx/1032104 to your computer and use it in GitHub Desktop.
Save alyx/1032104 to your computer and use it in GitHub Desktop.
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