Skip to content

Instantly share code, notes, and snippets.

@andrewsolomon
Created May 21, 2017 17:50
Show Gist options
  • Save andrewsolomon/dae97235cd67cbb0a979fa21e069ddf6 to your computer and use it in GitHub Desktop.
Save andrewsolomon/dae97235cd67cbb0a979fa21e069ddf6 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dump 'pp';
use feature 'say';
sub array_intersection {
my ($ra_x, $ra_y) = @_;
my @intersection;
foreach my $x (@$ra_x) {
foreach my $y (@$ra_y) {
if ($x == $y) {
push @intersection, $x;
}
}
}
my @sorted = sort(@intersection);
return \@sorted;
}
my $ra_first = [1,2,3,4,5,6];
my $ra_second = [2,4,6,8,10];
my $ra_intersection = array_intersection($ra_first, $ra_second);
say "The intersection of ".pp( $ra_first )." and ".pp($ra_second)." is ".
pp($ra_intersection);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment