Truty said:
David Squire a présenté l'énoncé suivant :
a word is valid if this word contain all caracteres in $carac_available
and no caracteres of $carac_notavailable
Yes, that was already clear. The question is, what do you want to do in
the special cases where the strings are empty? If $carac_available is
empty, does that mean that any word is OK so long as it does not contain
any characters from $carac_notavailable?
I think I can guess the behaviour you want. If I am right, this will do it:
----
#!/usr/bin/perl
use strict;
use warnings;
my $carac_available = 'eo';
my $carac_notavailable = 'hydngp';
while (my $ligne = <DATA>) {
chomp $ligne;
my $contains_all_carac_available = 1;
if ($carac_available) { # if $carac_available is empty, then there
# are no compulsory characters
$contains_all_carac_available &= ($ligne =~ /$_/) for split //,
$carac_available;
}
if (
($contains_all_carac_available
&& (!$carac_notavailable # if $carac_notavailable is empty,
# then all characters are OK
|| $ligne !~ /[$carac_notavailable]/
)
)
) {
print $ligne." | ";
}
}