1

Okay, this is a weird one.

All of our servers are using ActivePerl 5.8.8 and windows server 2003.

During some development, we ran into an issue where the script we were working on started throwing back CGI errors. No amount of printing headers would work, just constant CGI errors. The issue was relegated to one development server.

After a bunch of digging, I found that the issue is related to warnings. When perl throws certain warnings the page comes back from IIS with a bad CGI header and nothing in the body. Specifically the warning about concatenating an un-initialized string.

Here's the test script I'm using.

use strict;


Main();

sub Main {
  my $Web = new CGI;
    my $SQL = VIN::SQL->new('INDIGO');
  print $Web->header();
  print "Testing!";
  print "/r/n/r/n/";
  my ($Body, $Title) = ('', '');
    my $Page;
    eval{
        $Page = "";
        $Page  = $Web->param('Page');
        print "Page " . $Page;

    };
}

Adding a no warning statement will mean it runs. Adding the Page param will also mean it runs.

Any idea on what might be causing it? I would like to understand why before just adding a "no warning" statement and moving on, as if this happens in our live enviroment, I'd prefer not to add a no warnings; statement to every perl script in the system.

Thank you so much for all your help.

4

2 回答 2

2

$Page should not be undef, so || "" makes sure that empty string is assigned instead.

sub Main {
  my $Web = new CGI;
  my $SQL = VIN::SQL->new('INDIGO');
  print $Web->header();
  print "Testing!";
  print "/r/n/r/n/";
  my ($Body, $Title) = ('', '');

  my $Page = $Web->param('Page') || "";
  print "Page ". $Page;
}
于 2013-05-23T21:05:33.507 回答
1

Something is getting an error message that is heading to the server before print $Web->header(); is being invoked. This means the output to the server is something like:

Error on line 123: Cannot create foo
Content-Type: text/html; charset=ISO-8859-1

Testing

Which is a bad header.

An easy fix to the printing of the header to the earlier part of the code.

Swapping the lines:

  my $SQL = VIN::SQL->new('INDIGO');
  print $Web->header();

to

  print $Web->header();
  my $SQL = VIN::SQL->new('INDIGO');

Will likely fix the problem (of bad header) and instead print the error message that is being generated to the browser.

于 2013-05-24T16:39:32.193 回答