Ask a Question related to PERL Modules, Design and Development.
-
Mumia W. #1
Re: Strange syntax error
[email]tseitlin@gmail.com[/email] wrote:
Every time I tried to use the Switch module, it caused> 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:> String found where operator expected at test.pl line 14, near "case>> perl -c test.pl
> '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.
>
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.
Mumia W. Guest
-
Syntax error
I posted a question or two on this recently, and posts have been helpful. However, I have a new problem, and don't know what to do. To recap.... -
error : syntax error at or near $1 for over select rows
This is the error i am getting when calling select * from cas_reset_qi_changedate('CAS','2003-02-03' ERROR: syntax error at or near "$1" at... -
Check syntax gives strange errors
Two classes defined in two actionscripts: CollisionManager and CollidableInfo. Scripts are in the same package. CollisionManager creates an... -
syntax error ???
Hi, on login.php , we can see that : (...) $sql = "SELECT Login FROM logins WHERE Login='$fusername'"; $result = mysql_query($sql) or... -
Strange IRB Syntax Error
Hi, while playing around a bit I encountered this: irb(main):001:0> RUBY_VERSION "1.7.3" irb(main):002:0> class Trivial irb(main):003:1> ...



Reply With Quote

