Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

simX

macrumors 6502a
Original poster
May 28, 2002
765
4
Bay Area, CA
Does anybody know what would cause a perl program to spontaneously not print out things that it's supposed to? I'm currently making a perl script, and for some reason it just seems to ignore the first few print lines of a specific subroutine in my program.

If you go here, you'll note that it just shows a bunch of text, but it should actually be displaying a couple images and text inside a table. If you look at the source, it doesn't have a start HTML or BODY tags, and doesn't even have the HEAD tag even though I've explicitly issued a command to print that text.

The subroutine itself is horrendously long so I didn't particularly want to post it here, but I was wondering if anybody knew some places to check for this sort of error. There aren't any compilation errors, either -- it just ignores a bunch of print lines.

I'm about to start banging my head against the wall because of this problem. :\
 

Rower_CPU

Moderator emeritus
Oct 5, 2001
11,219
2
San Diego, CA
How about just the code immediately surrounding the print statements for the beginning HTML, HEAD and BODY tags?

Use the PHP button to insert the code so it won't be commented out by the BB system.
 

crenz

macrumors 6502a
Jul 3, 2003
619
27
Shanghai, China
There's loads of possible reasons. Can you show us some source code? Without source code, it is impossible to help you, I guess.

You might also try to get help at PerlMonks (http://www.perlmonks.com), a great Perl community. People there are very helpful (if you ask questions the right way).
 

simX

macrumors 6502a
Original poster
May 28, 2002
765
4
Bay Area, CA
I've narrowed down the problem to a couple of lines in the code:

PHP:
#print hidden("xminval",$xTickLabels{'0'}),hidden("xmaxval",$xTickLabels{'1'});
#print hidden("yminval",$yTickLabels{'0'}),hidden("ymaxval",$yTickLabels{'1'});

When I comment these two lines out (like they already are), everything displays fine. However, when I uncomment them (since they're necessary for the script to function correctly), the whole top part of the page just vanishes as if it were not printed at all.

Any ideas as to why these lines would cause this sort of problem?

(I would post surrounding code, but like I said, it probably wouldn't be of much use since it's so incredibly messy that I would have to explain everything.)

[EDIT: GRR! I explicitly printed out those values later on in the HTML, so I could see it in the part of the page that isn't cut off at the top. The values are valid! Moreover, these lines don't cause a problem when first loading the script, but they do once the user enters a value in a specific text box. I don't get it!]
 

simX

macrumors 6502a
Original poster
May 28, 2002
765
4
Bay Area, CA
*sigh*

The other thing I've tried is to replace the CGI module calls with straight HTML, and I find that I can get one of those hidden fields in the HTML with no problem. However, as soon as I allow another one to be in the HTML, the top part of the page gets cut off again. I'm totally confused!

Could the HTML itself be causing the problem? Or is it likely something wrong with my programming?

*sigh* If you want to see the script in action, go here. Note that it works fine when it first starts up, but then when you enter something in the chemical element box (for example, say, "Fe") and submit the bottom form, the problem will occur. But if I hide three of those four hidden fields, everything works fine. The values are valid, too. So I just don't understand what in the world could be going wrong.

[EDIT: Hmm. It seems that it's not just those specific lines. Commenting out any three hidden fields will solve the problem. Is there a limit to how many hidden fields you can use in an HTML file?!? That would be lame.]
 

firestarter

macrumors 603
Dec 31, 2002
5,506
227
Green and pleasant land
My guess is that you're putting something strange into the hidden fields. If you did something strange like put a single quote in one, you might take everything to the next quote out of the print statement.

Are you using cgi tainting?

If you use a regexp to filter the user input, you could then make sure that the input is valid.

Just a guess, but in a case like this I always focus on the differences between each (working and not working) run of your code. The only difference here is the new hidden values you're using.

Good luck!!
 

simX

macrumors 6502a
Original poster
May 28, 2002
765
4
Bay Area, CA
Originally posted by firestarter
My guess is that you're putting something strange into the hidden fields. If you did something strange like put a single quote in one, you might take everything to the next quote out of the print statement.

Are you using cgi tainting?

If you use a regexp to filter the user input, you could then make sure that the input is valid.

Just a guess, but in a case like this I always focus on the differences between each (working and not working) run of your code. The only difference here is the new hidden values you're using.

Good luck!!

See, the thing is, most of these hidden fields are there on the first run, anyway, which works fine. Commenting out lines that print any three hidden text fields make the script run fine on the part with which I'm currently having problems. So I don't think it can possibly be a problem with misplacing quotes or something like that.

This has got to be the most mind-boggling problem I've ever had.

P.S. Does anyone know how to get the CPAN installer to recognize a fink-install GD? That would help in testing this problem, so I could test it out offline (since I don't have Chart::plot installed on my local machine, which is required for the script, and also requires GD to be installed). Chart::plot keeps complaining that GD isn't there when it is.
 

simX

macrumors 6502a
Original poster
May 28, 2002
765
4
Bay Area, CA
Resolved!

One of the very nice users over at perlmonks.com solved the problem! All I needed to do was to enable autoflush, by issuing a

PHP:
$| = 1;

command at the beginning of my script (that's the pipe operator following the dollar sign).

Since I didn't know this, maybe it will help other people out, too. Here's a relevant link explaining what this does.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.