Hi,
I'm running RHEL version 3 and have written a script in Perl. The bulk of the script is a large switch statement. When I run this with 134 cases it runs fine, when I run it with 136 cases I get the error:
Bad switch statement (problem in the code block?) near <filename> line ###
I can't see what's wrong with the code because the line 135 is exactly the same as line 134 except that it stats with 'case 135' instead of 'case 136'. I've posted the code below. Does anyone know what is going on here. Thanks so much.
Code:
#!/usr/bin/perl -w
use Switch;
open(IN,"filename");
open(OUT,">filename_out");
$count=1;
while(<IN>) {
$i=1;
chomp($_);
print OUT "$_\n";
switch ($count) {
case 1 { for ($i=1; $i<=6; $i++) { print OUT "0\t0\t0\t0\t0\t0\n"; } }
case 2 { for ($i=1; $i<=1; $i++) { print OUT "0\t0\t0\t0\t0\t0\n"; } }
case 3 { for ($i=1; $i<=3; $i++) { print OUT "0\t0\t0\t0\t0\t0\n"; } }
case 4 { for ($i=1; $i<=1; $i++) { print OUT "0\t0\t0\t0\t0\t0\n"; } }
case 5 { for ($i=1; $i<=2; $i++) { print OUT "0\t0\t0\t0\t0\t0\n"; } }
case 6 { for ($i=1; $i<=3; $i++) { print OUT "0\t0\t0\t0\t0\t0\n"; } }
case 7 { for ($i=1; $i<=2; $i++) { print OUT "0\t0\t0\t0\t0\t0\n"; } }
...
case 134 { for ($i=1; $i<=3; $i++) { print OUT "0\t0\t0\t0\t0\t0\n"; } } }
if ($count == 135) { for ($i=1; $i<=6; $i++) { print OUT "0\t0\t0\t0\t0\t0\n"; } }
if ($count == 136) { for ($i=1; $i<=9; $i++) { print OUT "0\t0\t0\t0\t0\t0\n"; } }
$count++;
}
close(IN);
close(OUT);
Note that the last two if statements were because lines 135 and 136 wouldn't work in the case statement.
I've just discovered a weird problem. If I take the program as is and move it to a central location so more than one user could use it I get the 'Bad switch' error even though I don't get this error when I have the script in my home directory. Does anyone have any ideas on what could be causing this script to be so temperamental? Thanks so much.
-NifflerX