Dear Monks,
Is there another way to have the intersection of two lists ? Thanks a lot
Here is my code
#usr/bin/perl
use strict;
my $name_1 = q{list_1.txt};
my $name_2 = q{list_2.txt};
open my $INFILE_1, q{<}, $name_1 or die "Can't open $name_1 : $!";
open my $INFILE_2, q{<}, $name_2 or die "Can't open $name_2 : $!";
my @list_1;
while (my $line_1 = <$INFILE_1>){
$line_1 =~ s/\s+$//;
push @list_1, $line_1;
}
my @list_2;
while (my $line_2 = <$INFILE_2>){
$line_2 =~ s/\s+$//;
push @list_2, $line_2;
}
my @intersection;
my %count;
my $element;
my @two_lists = (@list_1,@list_2);
print STDOUT "@two_lists\n";
foreach $element(@two_lists){
$count{$element}++;
}
my $key;
my @KEYS = keys %count;
foreach $key(@KEYS){
if ($count{$key} == 1){
print STDOUT "$key;$count{$key}\n\n";
}
}
close $INFILE_1;
close $INFILE_2;
Here is the first file
car
train
plane
Here is the second file
boat
car
train