SilverBean
Programmer
I just ran into this twice tonight uploading and testing my application. The one usual place I run into it, but then this peculair app does some interesting processing. Which caused me to revisit this in another section of code because like my app doesn't work now.
So I really ran this under the microscope and I can't believe what I'm seeing. I really need a sanity check here.
The problem is comments in my Switch structure as in:
switch ($in{'formtype'})
{
case "newsubject"
{
TopLevelMenu();
}
case "processlogoff"
{
$mystuff{'formsusername'}="";
$mystuff{'formspassword'}="";
TopLevelMenu();
}
else
{
#TopLevelMenu();
#if (hello)
#{
TopLevelMenu();
}
}
So if I remove the commented lines the CGI runs fine and performs as intended. With the comment lines in as above I get the infamous Internal Server Error - my web host is kind enough to offer some diagnostic of my ailiing scripts and when I use them it says "Bad switch statement (problem in the code block?) near index.cgi line 401 could not fire up index.cgi'. It's not clear to me why line 401 is the culprit. The exact structure of my code is:
If ($x)
{
switch()
{
}
}
else
{
switch()
{
}
}
The commented lines are actually in the true case switch and line 401 is actually somewhere down in the false case switch. I assure you the code is syntax-fully correct and it ran fine on my local machine.
Now I've kind of exaggerated the above case and I realize it's probably not the best practice to comment out lines of code. But is there really anything fundamentally wrong in that would make the script not work? I assure you I can reproduce with other commented lines and not just the specific ones above. Some interesting things of note:
1. App ran fine locally on my machine so maybe it's related to a version of Perl/ Switch that my host is using.
2. I noticed a million character limit on CPAN about Switch.PM above which mysterious results would be seen. I've got a mystery alright. I'm no where near a million characters. I got about 12-20 cases in the switch statement though spread over about a hundred lines very similair to what your seeing above. The whole CGI is 951 lines long. Length/ size issues?
3. I did NOT post my complete code. When I try to simplify down to a small CGI with just a switch I've never seen the failure. Only seems to occur in the larger file AND is consistent with the larger file.
I noticed thread thread219-1317281. That fella had a switch with everything commented out. I'm wondering if the errors he was seeing WAS with or without the comments. That was 2 years old and closed tempted to try to E-Mail him and see what his resolution was.
I will admit I did scrutinize my cases and I did have some duplicate cases which I eliminated. My gut is telling me that the commented lines are really confusing Perl at some level of abstraction it may even be a sizing/ speed issue are those little iddy biddy pound signs getting dropped or not processed right?
My usual place of running into this problem is that I have a switch statement which sets variables based on whether I'm running locally or on the web. I can tell you for a fact do a /#case "something" { somefunction}/ too many times and Perl gets mad. I got fed up and now my app is strictly a web based one no more local switch. I can also do that for the other switches...I'll just have to make sure I pull all my comments out, but that is really to bad.
Am I overlooking some basic rules of etiquette here?
So I really ran this under the microscope and I can't believe what I'm seeing. I really need a sanity check here.
The problem is comments in my Switch structure as in:
switch ($in{'formtype'})
{
case "newsubject"
{
TopLevelMenu();
}
case "processlogoff"
{
$mystuff{'formsusername'}="";
$mystuff{'formspassword'}="";
TopLevelMenu();
}
else
{
#TopLevelMenu();
#if (hello)
#{
TopLevelMenu();
}
}
So if I remove the commented lines the CGI runs fine and performs as intended. With the comment lines in as above I get the infamous Internal Server Error - my web host is kind enough to offer some diagnostic of my ailiing scripts and when I use them it says "Bad switch statement (problem in the code block?) near index.cgi line 401 could not fire up index.cgi'. It's not clear to me why line 401 is the culprit. The exact structure of my code is:
If ($x)
{
switch()
{
}
}
else
{
switch()
{
}
}
The commented lines are actually in the true case switch and line 401 is actually somewhere down in the false case switch. I assure you the code is syntax-fully correct and it ran fine on my local machine.
Now I've kind of exaggerated the above case and I realize it's probably not the best practice to comment out lines of code. But is there really anything fundamentally wrong in that would make the script not work? I assure you I can reproduce with other commented lines and not just the specific ones above. Some interesting things of note:
1. App ran fine locally on my machine so maybe it's related to a version of Perl/ Switch that my host is using.
2. I noticed a million character limit on CPAN about Switch.PM above which mysterious results would be seen. I've got a mystery alright. I'm no where near a million characters. I got about 12-20 cases in the switch statement though spread over about a hundred lines very similair to what your seeing above. The whole CGI is 951 lines long. Length/ size issues?
3. I did NOT post my complete code. When I try to simplify down to a small CGI with just a switch I've never seen the failure. Only seems to occur in the larger file AND is consistent with the larger file.
I noticed thread thread219-1317281. That fella had a switch with everything commented out. I'm wondering if the errors he was seeing WAS with or without the comments. That was 2 years old and closed tempted to try to E-Mail him and see what his resolution was.
I will admit I did scrutinize my cases and I did have some duplicate cases which I eliminated. My gut is telling me that the commented lines are really confusing Perl at some level of abstraction it may even be a sizing/ speed issue are those little iddy biddy pound signs getting dropped or not processed right?
My usual place of running into this problem is that I have a switch statement which sets variables based on whether I'm running locally or on the web. I can tell you for a fact do a /#case "something" { somefunction}/ too many times and Perl gets mad. I got fed up and now my app is strictly a web based one no more local switch. I can also do that for the other switches...I'll just have to make sure I pull all my comments out, but that is really to bad.
Am I overlooking some basic rules of etiquette here?