tseitlin wrote:
> Hello,
> I get a syntax error I can't explain.
>
> The script (reduced version):
>
> ###############################
> use Switch;
>
> my $line;
> if ($line =~ /^Frequency\s+=\s+(\d+)\./){
> $freq = $1/1000000;
> }
>
> #sub for opening files in 'read', 'write' or 'append' mode
> sub openFile()
> {
> my ($file, $mode) = @_;
> local *FH;
> switch($mode){
> case 'r'{
> if(!open(FH , $file)){
> print"can't open $file $!";
> return 0;
> }
> }
> case 'w'{
> if(!open(FH , ">$file")){
> print"can't open $file $!";
> return 0;
> }
> }
> case 'a'{
> if(!open(FH , ">>$file")){
> print"can't open $file $!";
> return 0;
> }
> }
> else{
> print"wrong or unsupported mode: use 'r' or 'w'";
> return 0;
> }
> }
> return *FH;
> }
>
> # sub simple_stats {
> # my $mean = $sum_x / $size;
> # }
>
> ###END########
>
> The error message:
>> perl -c test.pl

> String found where operator expected at test.pl line 14, near "case
> 'r'"
> (Do you need to predeclare case?)
> syntax error at test.pl line 13, near "){"
> syntax error at test.pl line 19, near "}"
> test.pl had compilation errors.
>
> Eny of the following eliminates the error:
> 1. Removing or commenting :
> if ($line =~ /^Frequency\s+=\s+(\d+)\./){
> $freq = $1/1000000;
> }
> 2. Removing or commenting the openFile sub.
> 3. Removing the commented simple_stats sub !!!
>
> If any one has an idea, please help!
> Thanks.
>


Every time I tried to use the Switch module, it caused
me problems, so I don't use it any more. In particular,
Switch seems to be incompatible with mod_perl under
Apache.

My theory is that Switch interacts with the perl parser
behind the scenes, and since it's buggy, the effects of
its modifications to the parser are weird errors.

Don't use Switch.