为什么我会得到;重新定义;加上「」的警告;使用常量;在mod_perl下?

为什么我会得到;重新定义;加上「」的警告;使用常量;在mod_perl下?,perl,cgi,warnings,mod-perl,Perl,Cgi,Warnings,Mod Perl,我使用apache2运行CGI脚本,在error.log中有以下警告行(我从输出中删除了所有类似的行): 此代码具有类似的输出: $perl-e'sub FOO(){1}BEGIN{*FOO=sub(){2};}print FOO;' Constant subroutine main::FOO redefined at -e line 1. 常量子例程main::FOO在-e第1行重新定义。 我没有警告qw/redefinite/,但它没有帮助。猜测一下,FOO的第一个定义正在被优化。用正文中的

我使用apache2运行CGI脚本,在error.log中有以下警告行(我从输出中删除了所有类似的行):

此代码具有类似的输出:
$perl-e'sub FOO(){1}BEGIN{*FOO=sub(){2};}print FOO;'

Constant subroutine main::FOO redefined at -e line 1. 常量子例程main::FOO在-e第1行重新定义。
我没有警告qw/redefinite/
,但它没有帮助。

猜测一下,FOO的第一个定义正在被优化。用正文中的语句定义它,我想你会发现错误消失了


$perl-e'sub FOO(){print 1;}BEGIN{*FOO=sub(){2};}print FOO;'

AFAIK,只有在修改脚本,然后由
mod_perl
为符合内联条件的子例程重新编译脚本时,才会收到这些警告。重新编译子例程时,如果它返回的值发生更改,则新值不会反映在以前内联的位置

如果更改了值,例如,
BUFFER\u SIZE
,则应重新启动
apache

我也认为这与你的剧本有关



#!/usr/bin/perl
use strict;
use warnings;


use CGI;
use CGI::Carp;
#use diagnostics qw/-verbose/;

use Fcntl qw( :DEFAULT :flock );
use constant UPLOAD_DIR     => "/tmp/test_upload/";
use constant BUFFER_SIZE    => 16_384;
use constant MAX_FILE_SIZE  => 1_048_576;       # Limit each upload to 1 MB
use constant MAX_DIR_SIZE   => 100 * 1_048_576; # Limit total uploads to 100 MB
use constant MAX_OPEN_TRIES => 100;

$CGI::DISABLE_UPLOADS   = 0;
$CGI::POST_MAX          = MAX_FILE_SIZE;
my $q = new CGI;
$q->cgi_error and error( $q, "Error transferring file: " . $q->cgi_error );
my $file      = $q->param( "file" )     || error( $q, "No file received." );
my $filename  = $q->param( "filename" ) || error( $q, "No filename entered." );
my $fh        = $q->upload( "file" )     || error( $q, "Something is wrong with file handle." );
#my $fh        = $q->upload( $file );
my $buffer    = "";
if ( dir_size( UPLOAD_DIR ) + $ENV{CONTENT_LENGTH} > MAX_DIR_SIZE ) {
    error( $q, "Upload directory is full." );
}
# Allow letters, digits, periods, underscores, dashes
# Convert anything else to an underscore
$filename =~ s/[^\w.-]/_/g;
if ( $filename =~ /^(\w[\w.-]*)/ ) {
    $filename = $1;
}
else {
    error( $q, "Invalid file name; files must start with a letter or number." );
}
# Open output file, making sure the name is unique
until ( sysopen OUTPUT, UPLOAD_DIR . $filename, O_CREAT | O_EXCL ) {
    $filename =~ s/(\d*)(\.\w+)$/($1||0) + 1 . $2/e;
    $1 >= MAX_OPEN_TRIES and error( $q, "Unable to save your file." );
}
# This is necessary for non-Unix systems; does nothing on Unix
binmode $fh;
binmode OUTPUT;
# Write contents to output file
while ( read( $fh, $buffer, BUFFER_SIZE ) ) {
    print OUTPUT $buffer;
}
close OUTPUT;

if ( -T $fh ) {
    print $q->header("text/plain");
    seek $fh, 0, 0;
    map { print } ;
}

sub dir_size {
    my $dir = shift;
    my $dir_size = 0;

    # Loop through files and sum the sizes; doesn't descend down subdirs
    opendir DIR, $dir or die "Unable to open $dir: $!";
    while ( $_ = readdir DIR ) {
        $dir_size += -s "$dir/$_";
    }
    return $dir_size;
}
sub error {
    my( $q, $reason ) = @_;

    print $q->header( "text/html" ),
          $q->start_html( "Error" ),
          $q->h1( "Error" ),
          $q->p( "Your upload was not procesed because the following error ",
                 "occured: " ),
          $q->p( $q->i( $reason ) ),
          $q->end_html;
    exit;
}

Constant subroutine main::FOO redefined at -e line 1.