use diagnostics; use warnings; my ($file_dictionary, $word, $line, $line1, $alph, $elt, $w, $transposition, $letter1, $letter2); my (@word, @altered_word, @filedictionary, @filetext, @dictionary, @addition, @replacement, @transposition, @removal); $file_dictionary = "lexique.txt"; $file_text = "texte.txt"; #I create an array for the dictionary open (L, "<", $file_dictionary); while (defined( $line1 = )) { chomp($line1); @filedictionary = split (/\s/, $line1); push (@dictionary, @filedictionary); } #I create an array for the text open (T, "<", $file_text); while (defined( $line = )) { chomp($line); @filetext = split (/(\s|\pP)/, $line); for ($i = 0; $i < @filetext; $i++) { if (!grep(/^$filetext[$i]$/, @dictionary)) { push (@word, $filetext[$i]); } } } #then I create an array for each word foreach $w(@word) { @altered_word = split (//, $w); #I create an array for the dictionary open (L, "<", $file_dictionary); while (defined( $line1 = )) { chomp($line1); @filedictionary = split (/\s/, $line1); push (@dictionary, @filedictionary); } #first operation --> "palrer" will be "parler" for (my $i=0; $i < $#altered_word ; $i++) { @transposition = @altered_word; $letter1 = $transposition[$i]; $letter2 = $transposition[$i+1]; $transposition[$i] = $letter2; $transposition[$i+1] = $letter1; $transposition = join "", @transposition; if (grep(/^$transposition$/, @dictionary)) { print "post transposition : $transposition\n"; } } foreach $elt (0 .. $#altered_word) { #second operation --> parller will be parler @removal = @altered_word; splice(@removal, $elt, 1); $removal = join "", @removal; if (grep(/^$removal$/, @dictionary)) { print "post enlevement : $removal\n"; } #third operation --> parer will be parler foreach $alph('a' .. 'z') { @addition = @altered_word; splice(@addition, $elt, 0, $alph); $addition = join "", @addition; if (grep(/^$addition$/, @dictionary)) { print "post addition : $addition\n"; } #last operation : mancer will be manger @replacement = @altered_word; splice(@replacement, $elt, 1, $alph); $replacement = join "", @replacement; if (grep(/^$replacement$/, @dictionary)) { print "post replacement : $replacement\n"; } } } }