#!/usr/bin/perl use strict; use warnings; open my $listaParole,"File_Input/Coppie_Parole.txt" or die; my %hash; while (my $line=<$listaParole>) { chomp $line; my ($word1, $word2) = split /:/, $line; $hash{$word1} = $word2; } close $listaParole; open my $testo, "Wiki_Pulito/Prova/Conteggio1.txt" or die; my $count=0; my %arrayris; while (my $text=<$testo>){ for my $key (keys %hash){ my $value = $hash{$key}; if ($text =~/($key\/$key\/S)\s{0,4}(\.\*)\s{0,4}(con\/con\/E)\s{0,4}(\.\*)\s{0,4}($value\/$value\/S)\b/g){ $count++; } my $arrkey=$key."-".$value; $arrayris{$arrkey}=$count; } } while ( my ($k,$v) = each %arrayris ) { print $conteggio "($k) => $v\n"; } close $testo; close $conteggio; #### ([aA]mplificator[ei]-[Tt]ransistor) => 27 ([cC]ervello-[Tt]alamo) => 27 ([Ee]ucariot[ia]-[Mm]embran[ae]) => 27 ([Cc]erio-[Ii]sotop[oi]) => 27 ([Cc]ellul[ae]-[Nn]ucle[oi]) => 27 ([Tt]ronco-[Tt]orace) => 27 ([Bb]raccio-[Aa]vambraccio) => 27