1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| #!/usr/bin/perl
use strict;
use warnings;
my $file1 = <<FILE;
chirac prime paris
chirac prime jacques
chirac prime president
chirac paris france
chirac paris french
FILE
my $file2 = <<FILE;
chirac presidential migration
chirac presidential paris
chirac prime president
chirac presidential 007
chirac paris migration
chirac paris french
FILE
#open my $inA, '<', $ARGV[0] or die "Can;t open $ARGV[0]: $!\n";
#open my $inB, '<', $ARGV[1] or die "Can;t open $ARGV[0]: $!\n";
open my $inA, '<', \$file1;
open my $inB, '<', \$file2;
#print "bonjour\n";
#print "choose the output file name\n";
#
#chomp(my $fic2 = <STDIN>);
#open my $outFile, '>', $fic2 or die "Can't create $fic2: $!\n";
my @aLines;
while (my $ligne = <$inA>) {
chomp $ligne;
push @aLines, lc($ligne);
}
while (my $che = <$inB>) {
chomp $che;
my @bWords = split(/\s/, $che);
foreach my $kh (@aLines) {
my @aWords = split(/\s/, $kh);
my $total = 0;
for my $bWord (@bWords) {
my $matched;
for my $aWord (@aWords) {
$matched = $bWord eq $aWord;
last if $matched;
}
$total++ if $matched;
}
#print the retrieved line
#print $outFile "$.: $kh\n";
if ($total>1)
{print "$.: $kh\n";}
}
} |
Partager