perl包中未定义的子例程错误

时间:2015-07-30 21:57:51

标签: perl

这是主文件upload.cgi

#!/usr/bin/perl
use strict;
use lib '.';
use XFSConfig;
use XUpload ; 
use CGI::Carp qw(fatalsToBrowser);
use CGI;
use Fcntl ':flock';
use LWP::UserAgent;
use HTTP::Cookies;
use HTML::Form;
use Encode;
        sub xmessage
    {
       my ($msg) = @_;
       &lmsg($msg);
       $msg=~s/'/\\'/g;
       $msg=~s/<br>/\\n/g;
       print"Content-type: text/html\n\n";
       print"<HTML><HEAD><Script>alert('$msg');</Script></HEAD><BODY><b>$msg</b></BODY></HTML>";
       exit;
    }

    sub lmsg
    {
       my $msg = shift;
       open(F,">$c->{htdocs_tmp_dir}/$sid.html");
       print F qq[new Object({"state":"error", "msg":"$msg"})];
       close F;
       &logit($msg);
    }

并且此函数调用函数

 &XUpload::ProcessFile()

和XUpload :: ProcessFile()函数调用函数&amp; xmessage(“Fatal”);在upload.cgi中定义

现在我收到此错误

Undefined subroutine &XUpload::xmessage called at Modules/XUpload.pm line 17.

似乎包XUpload无法找到upload.cgi中定义的函数xmessage

1 个答案:

答案 0 :(得分:0)

cgi脚本中的xmessage sub在main包中定义,而XUpload模块(显然)在XUpload命名空间中运行。

解决此问题最终将涉及了解Perl的命名空间和Exporter模块。但快速而又脏的修复方法是在XUpload包中为您的sub创建别名。将此行添加到主脚本:

*XUpload::xmessage = *message;