I just wanted to follow-up a second time to point out something that I think is a lot more of a valuable lesson than any of the answers you've received, taken individually.
You've just witnessed a thought-process in action. Your script didn't work as you expected. We took a look at it and each came up with a different suggestion. But each was a suggestion that, applied in a more general sense, begins to answer the more important question of "how do I figure out what's going wrong, when something goes wrong?"
One answer is always check return values. Another answer is to develop your scripts under strictures (use strict;) and warnings (use warnings;). Another answer was to use CGI::Carp. Another answer (correctly) pointed you at the issue of opening a filehandle but reading from the <> diamond operator (sans named filehandle). And another was to look more closely at a means of simplifying the logic of your if-else statements.
Collectively these represent a process of programming in such a way that Perl tells you what's wrong, and in such a way that is less likely to develop hard to find errors. Many of the "why doesn't this work" questions posted here end up with a similar thought-process zeroing in on the problem. The implication is that many of the "why doesn't this work" questions a person has regarding his script, he can answer himself by applying the practices and thought processes that simplify debugging: Checking return values, simplifying logic, using strict, using warnings, using Carp (where applicable), using lexical filehandles (which are beneficial for many reasons not the least of which is the fact that a lexical filehandle must pass strictures), and so on. Tackle the bigger issue and the smaller ones fall into place.
This is just a thought that hopefully someone will find entertaining.... not quite worthy of being a meditation, but possibly worthy of mention. ;)
Dave
In reply to Re: Interesting CGI Problem...
by davido
in thread Interesting CGI Problem...
by Spidy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |