I have programmed a Perl script which has two input files:
The first file has on each line phrase and then a value between parentheses. Here an example:
hello all (0.5) hi all (0.63) good bye all (0.09)
The second file has a list of rules. For example:
hello all -> salut (0.5) hello all -> salut à tous (0.5) hi all -> salut (0.63) good bye all -> au revoir (0.09) good bye -> au revoir (0.09)
The script has to read the second file and for each line it extracts the phrase before the arrow (e.g. for the 1st line: hello all
) and it will check if this phrase is present in the first file (in our example here it is found).
If it is present it write the whole line hello all -> salut (0.5)
to the output.
So in this example the output file should be:
hello all -> salut (0.5)
hello all -> salut à tous (0.5)
hi all -> > salut (0.63)
good bye all -> au revoir (0.09)
My idea is to put all the contents of the first file into a hash table. For this here my script:
#!/usr/bin/perl
use warnings;
my $vocabFile = "file1.txt";
my %hashFR =();
open my $fh_infile, '<', $InFile or die "Can't open $InFile\n";
while ( my $Ligne = <$fh_infile> ) {
if ( $Ligne =~ /(/ ) {
my ($cle, $valeur) = split /(/, $Ligne;
say $cle;
$h{$cle} = $valeur;
}
}
My question now: how do I extract the segment of word just before the arrow and search for it in the hash table?
Thank you for your help