PDA

View Full Version : switch statements inside perl module?


super_gunda
06-15-2007, 08:42 PM
Hi,

I get the following error message when I try using "switch" in perl module

"String found where operator expected at /usr/lib/perl5/site_perl/VMK/VMKC.pm line 393, near "case "info ""
(Do you need to predeclare case?)
Did not find leading dereferencer, detected at offset 6488syntax error at /usr/lib/perl5/site_perl/VMK/VMKC.pm line 392, near ") {"
syntax error at /usr/lib/perl5/site_perl/VMK/VMKC.pm line 396, near "}"
Compilation failed in require at (eval 1) line 3.
...propagated at /usr/lib/perl5/5.8.0/base.pm line 64.
BEGIN failed--compilation aborted at ./IOZone.pl line 62.
":eek:

VMKC.pm :-
-----------------

sub WriteTestLog
{
my $type = "info";
switch ($type) {
case "info" {
print "info";
}
}
}

I am calling this function from IOZone.pl.
If I remove switch statement it works.

Thanks,
R

bazz
06-16-2007, 11:36 AM
what that you are trying to do with info? I don't think there is a switch command in perl but I expect there is something that will do what you need.

not sure about your syntax either and this is confirmed in your error mesaage.

bazz

ralph l mayo
06-16-2007, 11:36 AM
Perl doesn't have the switch keyword. You can do this instead: http://www.perlmeme.org/howtos/syntax/switch_statements.html
There's also a switch add-on in CPAN, and I hear Larry is working on cramming some more punctuation into the concept in time for its inclusion with Perl 6.

KevinADC
06-17-2007, 05:18 AM
might work if you load the swich module:

use Switch;