From: David Squire on
Truty wrote:
>
> 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;

---- Attempting to run this produces -----

Backslash found where operator expected at ./test2.pl line 17, near "]\"
(Missing operator before \?)
Backslash found where operator expected at ./test2.pl line 17, near "]\"
(Missing operator before \?)
syntax error at ./test2.pl line 7, near "$sayword["
syntax error at ./test2.pl line 17, near "]\"
Global symbol "$ligne" requires explicit package name at ./test2.pl line 17.
syntax error at ./test2.pl line 20, near "}"
Execution of ./test2.pl aborted due to compilation errors.

----

This code contains the same errors that I pointed out in your original
post, as well as some new ones. Please read my post and make the
necessary changes before posting again.

You really should not post code that won't compile. The error messages
from the compiler and Perl's own documentation should get you past
syntax errors. I suggest that you read an introductory book on Perl, and
also become familiar with the documentation that comes with Perl. For a
start, try reading

perldoc perldata
perldoc perlre


DS
From: David Squire on
David Squire wrote:
> Truty wrote:

[snip]

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

[snip]

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

Clarification: you can't use backslashes as the delimiters without an
operator such as "m" being used at the start, e.g.

if (($ligne =~ /[$carac_available]/) && ($ligne !~
/[$carac_notavailable]/) ) { print $ligne." | "; }

is OK, and so is

if (($ligne =~ m\[$carac_available]\]) && ($ligne !~
m\[$carac_notavailable]\) ) { print $ligne." | "; }


DS

From: David Squire on
David Squire wrote:
> David Squire wrote:
>> Truty wrote:
>
> [snip]
>
>>> if (($ligne =~ \[$carac_available]\) && ($ligne !~
>>> \[$carac_notavailable]\) ) { print $ligne." | "; }
>
> [snip]
>
>> This will not even compile. You can't use backslashes as regex
>> delimiters. The compiler should have told you that.
>
> Clarification: you can't use backslashes as the delimiters without an
> operator such as "m" being used at the start, e.g.
>
> if (($ligne =~ /[$carac_available]/) && ($ligne !~
> /[$carac_notavailable]/) ) { print $ligne." | "; }
>
> is OK, and so is
>
> if (($ligne =~ m\[$carac_available]\]) && ($ligne !~
> m\[$carac_notavailable]\) ) { print $ligne." | "; }

Arggh. That should be

if (($ligne =~ m\[$carac_available]]\) && ($ligne !~
m\[$carac_notavailable]\) ) { print $ligne." | "; }
From: Truty on
David Squire avait ?nonc? :
> Truty wrote:
>>
>> 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;
>
> ---- Attempting to run this produces -----
>
> Backslash found where operator expected at ./test2.pl line 17, near "]\"
> (Missing operator before \?)
> Backslash found where operator expected at ./test2.pl line 17, near "]\"
> (Missing operator before \?)
> syntax error at ./test2.pl line 7, near "$sayword["
> syntax error at ./test2.pl line 17, near "]\"
> Global symbol "$ligne" requires explicit package name at ./test2.pl line 17.
> syntax error at ./test2.pl line 20, near "}"
> Execution of ./test2.pl aborted due to compilation errors.
>
> ----
>
> This code contains the same errors that I pointed out in your original post,
> as well as some new ones. Please read my post and make the necessary changes
> before posting again.
>
> You really should not post code that won't compile. The error messages from
> the compiler and Perl's own documentation should get you past syntax errors.
> I suggest that you read an introductory book on Perl, and also become
> familiar with the documentation that comes with Perl. For a start, try
> reading
>
> perldoc perldata
> perldoc perlre
>
>
> DS

sorry :( but now there aren't error when you compile.

A complable code :

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

# in @sayword is recording words already say
# sample sayword : 'abcde' , 'kjuhy', '12345, 'KJITR' ...
my @sayword;
$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) && ($line !~ $carac_notavailable)) {
print $line." | "; # display word available
}
}
close FILE;


From: Matt Garrish on

David Squire wrote:

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

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

You can't use backslashes as a delimiter without specifying m\\, but
that's true for all non-standard delimiters.

Matt