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 65 66 67 68 69 70
| #!/usr/local/bin/perl
use warnings;
use strict;
use Data::Dump qw(dump);
my $start_time;
start_timer();
# my $dico_file = 'liste.de.mots.francais.frgut.txt'; #original dictionary
my $dico_file = 'inf_6.txt'; #6 max length word dico
###################################
#input
my $find = lc($ARGV[0]);
my %chars_ct;
foreach my $char (split(//, $find)) {
$chars_ct{$char}++;
}
###################################
# print "Cherche des mots\n";
my $dico;
my %alpha_ct;
my $manon;
my $flag;
my %result;
my $handle = open_file($dico_file);
#to construct a 6 max length word dico
# open(OUT, ">inf_6.txt");
while (my $line = <$handle>) {
$line =~ s/\r//;
chomp $line;
if ($line eq '') { next; }
#to construct a 6 max length word dico
# if (length($line) <= 6) { print OUT lc($line), "\n"; }
# next;
my %alpha_ct;
$flag = 1;
foreach my $char (split(//, $line)) {
$alpha_ct{$char}++;
}
foreach my $char (keys %alpha_ct) {
if (!defined($chars_ct{$char}) || ($alpha_ct{$char} > $chars_ct{$char})) {
$flag = 0;
last;
}
}
if ($flag == 1) {
push @{ $result{length($line)} }, $line;
}
}
#to construct a 6 max length word dico
# close OUT;
close($handle);
my $ct = 0;
foreach my $length (sort {$b<=>$a} keys %result) {
foreach my $word (@{ $result{$length} }) {
$ct++;
print "\t$word\n";
}
} |