Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comments in my Switch

Status
Not open for further replies.

SilverBean

Programmer
May 23, 2001
44
US
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?






 
Use the CGI::Carp module and see if you get a more descriptive error returned:

use CGI::Carp qw/fatalsToBroswer/;

If not, the script is probably failing to compile for reasons unkown at this time.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks for your response. It was very diplomatic. I hope your able to use your literary talents for good and not evil. Fatals to browser -- that's my standard, no help. I saw your post about 5.10.1 I thought I would get the token upgrade speech but I kind of have to use whatever my host provides right now which BTW is 5.8.3

I've always gotten good information here. I like Perl and it's nice to get an honest answer. Though as closely as I've scrutinized my code over this weekend I'm sure its by no means the best. I'm holding out hope that maybe because my XHTML syntax is not the best (and thats mainly due to laziness as opposed to anything else) my theory is the browser is not happy with the output coming from my perl script.

The problem is right now I have a web site that can't go live because of this. Everytime I sit down to rewrite it I get writers block because I don't know what I'm changing in order to work around this issue. I had 2-3 applications based on this core code and these updates are not going to happen now until I get this resolved.

My web site host is going to find an interesting question when they arrive tomorrow. It's a shame I can't post here but the files are just to big. And no one would believe me. What I've seen recently I'm not convinced it has anything to do with the Switch statement at all. There are 2 files ok.cgi, and bad.cgi the ONLY difference in the files of some 951 lines is line 127 which is

#print "<input type=\"hidden\" name=\"formtype\" value=\"about\" > ";

Yep thats right a commented line. When I run ok.cgi it does something expected, bad.cgi gives me the aforementioned
"Bad switch statement (problem in the code block?) near index.cgi line 399 could not fire up bad.cgi'

This is also an example of my sloppy XHTML in that I believe an ending / is appropriate. BUT from Perl perspective it's a commented line? Right?

Line 399 is actually the last statement in my else block of one of my many (actually 2 or 3) switch-es. In fact it might be the last switch. I think the question to my
web host is appropriate because this is actually their error message that I'm quoting here. This occurs in IE V6.0 SP 1 and NNV9.0.

The only reasonable way to get this to anybody by way of this board is by zip at j5services.netfirms.com/fortektips/myJan08issue.zip
It will be available there for the next 24-48 hours from the time of this post. I'm so upset I've lost track of what day it is :) got the year right though.

Despite my best efforts to try to shorten this code down -- at the reduced level the error just seems to vanish.

I'm not expecting ANYBODY to crawl through this code and find a syntax error. I'm also not expecting anybody to take a chance on a zip file form such a source as this(my own web site).

I am still holding out hope I can learn something here though. If somebody is willing to teach I would listen to reasonable feedback.
 
 http://j5services.netfirms.com/fortektips/myJan08issue.zip
The Switch module has to actually parse the perl code, evidently it is getting triped up by the commented lines. Remove all commented lines from within switch/case blocks and see if that helps, and fix the missing quote in this line (225):

Code:
					print "<input type=\"hidden\" name=\"formtype\" value=\successnewlogin\" >\n";

should be:

Code:
					print "<input type=\"hidden\" name=\"formtype\" value=\[red]"[/red]successnewlogin\" >\n";

That will get rid of the "Unrecognized escape \s .... at line 225" warning.

Another person reported that comments in the switch code caused the code to not work. Did you check the bug reports on CPAN?

If you were trying to be funny in your opening comments, it came across as sarcastic. Keep the stupid and gratuitous remarks to yourself next time. Now I am being diplomatic. Next time you get your thread red-flagged and removed. Dave, the guy that runs the site, has little patience for jerks. If you want to continue asking for help on Tek-Tips I suggest you change your attitude.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top