From: Truty on
Hi,

Please help me,
I would like to realise a filtre to select only word in file with
caracteres include into this variable $carac_available;
but not caracteres include into this variable $carac_notavailable;

my name file is "dico.txt"

sample with $carac_available = 'eo'; and $carac_notavailable =
'hydngp';
word selected : close, mouve, ... because 'o' and 'e' is include into
this words and 'h', 'y', 'd', 'n', 'g', 'p' is not include into this
words.

content dico.txt :
doing
close
sunny
drugs
mouve
....


my code with problem :
open (FILE_ANSWER,"dico.txt.txt");
while ($ligne = <FILE_ANSWER>) {
chomp($ligne);
if (($ligne =~ \[$carac_available]\) && ($ligne !~
\[$carac_notavailable]\) ) { print $ligne." | "; }
}
close FILE_ANSWER;



Please, can you please me ?


From: David Squire on
Truty wrote:
> Hi,
>
> Please help me,
> I would like to realise a filtre to select only word in file with
> caracteres include into this variable $carac_available;
> but not caracteres include into this variable $carac_notavailable;
>
> my name file is "dico.txt"
>
> sample with $carac_available = 'eo'; and $carac_notavailable = 'hydngp';
> word selected : close, mouve, ... because 'o' and 'e' is include into
> this words and 'h', 'y', 'd', 'n', 'g', 'p' is not include into this words.
>
> content dico.txt :
> doing
> close
> sunny
> drugs
> mouve
> ...
>
>
> my code with problem :

missing:

use strict;
use warnings;

> open (FILE_ANSWER,"dico.txt.txt");

Is this your real code? That filename does not match the one above, and
you really, really must check that the open was successful. This would
be much better:

open my $FILE_ANSWER, '<', 'dico.txt' or die "Could not open dico.txt
for reading: $!";

> while ($ligne = <FILE_ANSWER>) {
> chomp($ligne);
> if (($ligne =~ \[$carac_available]\) && ($ligne !~
> \[$carac_notavailable]\) ) { print $ligne." | "; }

$carac_available and $carac_available are not defined in this example.
Please post a *complete* script that we can run and test. Cut-and-paste
the code, don't retype it.

This will not even compile. You can't use backslashes as regex
delimiters. The compiler should have told you that.

You would probably be better off creating compiled regular expression
variables rather than strings. See my example below.

> }
> close FILE_ANSWER;
>

----

#!/usr/bin/perl

use strict;
use warnings;

my $carac_available = qr([eo]);
my $carac_notavailable = qr([hydngp]);

while (my $ligne = <DATA>) {
chomp $ligne;
if (($ligne =~ $carac_available) && ($ligne !~ $carac_notavailable)) {
print $ligne." | ";
}
}

__DATA__
doing
close
sunny
drugs
mouve
botts

----

Output:

close | mouve | botts |

----


DS
From: Truty on
Thanks David,


I try to select more code for help me but I can't to copy and paste all
code.

Wait ... ;)


From: David Squire on
Truty wrote:
> Thanks David,
>
>
> I try to select more code for help me but I can't to copy and paste all
> code.


Please quote context when you reply. See the posting guidelines for this
group, which are posted here regularly.


DS
From: Truty on
Truty avait soumis l'id?e :
> Hi,
>
> Please help me,
> I would like to realise a filtre to select only word in file with caracteres
> include into this variable $carac_available;
> but not caracteres include into this variable $carac_notavailable;
>
> my name file is "dico.txt"
>
> sample with $carac_available = 'eo'; and $carac_notavailable = 'hydngp';
> word selected : close, mouve, ... because 'o' and 'e' is include into this
> words and 'h', 'y', 'd', 'n', 'g', 'p' is not include into this words.
>
> content dico.txt :
> doing
> close
> sunny
> drugs
> mouve
> ...
>
>
> my code with problem :
> open (FILE_ANSWER,"dico.txt.txt");
> while ($ligne = <FILE_ANSWER>) {
> chomp($ligne);
> if (($ligne =~ \[$carac_available]\) && ($ligne !~ \[$carac_notavailable]\)
> ) { print $ligne." | "; }
> }
> close FILE_ANSWER;
>
>
>
> Please, can you please me ?

CODE :

#!/usr/bin/perl
use strict;
use warnings;

# in @sayword is recording words already say
# sample sayword : 'abcde' , 'kjuhy', '12345, 'KJITR' ...
my $sayword[0]= 'abcde'; # for test
# caracteres false is in this string
my $carac_notavailable = 'zwxvbdsau'; # for test
# caracteres OK is in this string
my $carac_available = 'cea'; # for test
my $line;
my $fileanswer = length($sayword[0]); # to select the file '4
caracteres' or '5 caracteres' or ......
open (FILE,"$fileanswer.txt"); # file = 4.txt or 5.txt or ....
while ($line = <FILE>) {
chomp($line);
if (($line =~ \[$carac_available]\) && ($ligne !~
\[$carac_notavailable]\)) {
print $line." | "; # display word available
}
}
close FILE;




I hope to help me ...