0

I am new to perl. I am running a perl script on macbook and i get following error:

Can't locate CGIBook/Error.pm in @INC (@INC contains: /Library/Perl/5.12/darwin-thread-
multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level
/Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.3 /System/Library/Perl/5.12/darwin-
thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-
thread-multi-2level /System/Library/Perl/Extras/5.12) at HW1_3A.pl line 5.

It looks like I don't have CGIBook in my perl directory. Is that correct? Can anyone help me with this?

4

1 回答 1

1

我没有在 CPAN 上找到CGIBook::Error,因此它可能是本地模块或您从供应商那里获得(或应该获得)的东西。可能有人安装在默认模块搜索路径以外的其他位置。

在这种情况下,看起来您可能正在尝试使用古老书籍CGI Programming with Perl中的示例,该示例为示例创建了一个具有相同名称的模块。

谷歌搜索错误消息很快导致了这个代码:

#!/usr/bin/perl -wT

package CGIBook::Error;

# Export the error subroutine
use Exporter;
@ISA = "Exporter";
@EXPORT = qw( error );

$VERSION = "0.01";

use strict;
use CGI;
use CGI::Carp qw( fatalsToBrowser );

BEGIN {
    sub carp_error {
        my $error_message = shift;
        my $q = new CGI;
        my $discard_this = $q->header( "text/html" );
        error( $q, $error_message );
    }
    CGI::Carp::set_message( \&carp_error );
}

sub error {
    my( $q, $error_message ) = @_;

    print $q->header( "text/html" ),
          $q->start_html( "Error" ),
          $q->h1( "Error" ),
          $q->p( "Sorry, the following error has occurred: " ),
          $q->p( $q->i( $error_message ) ),
          $q->end_html;
    exit;
}

1;
于 2013-04-20T21:11:22.423 回答