Hello!
This is a sample code:
#!/usr/bin/perl -w
use strict;
use Switch;
my $var = 13/6;
#my $var = division(13, 6);
sub switchBug{
my $input = shift();
switch( $input ){
case 1 {print "One";}
case 2 {print "Two"; }
else{print "A lot";}
}
}
sub division{
my $a = shift;
my $b = shift;
return $a/$b;
}
When I use division
my $var = 13/6;
somewhere in the code ABOVE a switch statement, I receive error:
Number found where operator expected at ./switch.pl line 10, near "case 1"
(Do you need to predeclare case?)
Number found where operator expected at ./switch.pl line 11, near "case 2"
(Do you need to predeclare case?)
syntax error at ./switch.pl line 9, near "){"
syntax error at ./switch.pl line 11, near "case 2"
Execution of ./switch.pl aborted due to compilation errors.
When I comment line with "direct" division or the whole switch
statement, it is OK. (I can use division subroutine as shown - when it's
defined below a switch statement in the code, it work, but it's ugly...)
================
uname -a
Linux coder-4 2.6.15-1-686 #2 Thu Feb 2 18:29:01 UTC 2006 i686 GNU/Linux
perl -v
This is perl, v5.8.8 built for i486-linux-gnu-thread-multi
switch.pm: $VERSION = '2.10_01';
With regards
Petr Chlupaty