T
tseitlin
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:
'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.
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 "caseperl -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.