...

View Full Version : problem with perl modules and cgi script



dark0s
02-23-2010, 08:44 PM
I writed a little perl/cgi script /usr/lib/cgi-bin/createproject.cgi:

#!/usr/bin/perl -w
use strict;

# MyModule.pm is in my home directory

use lib "/my/home/directory/";
use MyModule;
use CGI;


my $cgi = CGI->new();

print $cgi->header();

my $pname = $cgi->param('projname');

print 'pname = '.$pname."\n";

my $mProject = new MyModule;

$mProject->create($pname);

/var/log/apache2/error.log file is:

Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 7.
Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 8.
Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 9.
Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 13.
Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 31.
Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 41.
Compilation failed in require at /usr/lib/cgi-bin/createproj.cgi line 5.
BEGIN failed--compilation aborted at /usr/lib/cgi-bin/createproj.cgi line 5.
[Tue Feb 23 21:38:03 2010] [error] [client 127.0.0.1] Premature end of script headers: createproj.cgi, referer: http://localhost/projects.html

In Firefox appears "500 Internal Server Error".

What is the problem?

FishMonger
02-23-2010, 09:36 PM
You forgot to declare $self (with the 'my' keyword) before using it.

dark0s
02-23-2010, 10:23 PM
I declared self with my keyword but /var/log/apache2/error.log is:

Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 7.
Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 8.
Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 9.
Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 13.
Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 31.
Global symbol "$self" requires explicit package name at /usr/lib/perl/5.10/MyModule.pm line 41.
Compilation failed in require at /usr/lib/cgi-bin/createproj.cgi line 5.
BEGIN failed--compilation aborted at /usr/lib/cgi-bin/createproj.cgi line 5.
[Tue Feb 23 23:21:21 2010] [error] [client 127.0.0.1] Premature end of script headers: createproj.cgi, referer: http://localhost/projects.html

FishMonger
02-23-2010, 10:51 PM
Please post the code in /usr/lib/perl/5.10/MyModule.pm

dark0s
02-23-2010, 11:09 PM
I changed something.
In firefox appears 500 Internal Server Error

MyModule.pm is:

#!/usr/bin/perl
use strict;

package MyModule;

sub new {
my $self = {};
bless $self, "MyModule";
return $self;
}

sub create {
my $self = shift;
my $dir = shift;
chdir "/home/savio/" or die "Cannot chdir: $!";
mkdir $dir or die "Cannot mkdir: $!";
}

1;

and my script is /usr/lib/cgi-bin/myscript.cgi:


#!/usr/bin/perl -w
use strict;

use lib '/home/savio';
use MyModule;
use CGI;
use CGI::Carp qw(fatalsToBrowser);


my $cgi = CGI->new();

my $pname = $cgi->param('projname');
my $var = new MyModule;
$var->create($pname);

and /var/log/apache2/error.log is:

Can't locate MyModule.pm in @INC (@INC contains: /home/savio /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at /usr/lib/cgi-bin/myscript.cgi line 5.
BEGIN failed--compilation aborted at /usr/lib/cgi-bin/myscript.cgi line 5.
[Wed Feb 24 00:45:39 2010] [error] [client 127.0.0.1] Premature end of script headers: myscript.cgi, referer: http://localhost/projects.html

with MyModule.pm that it is in /home/savio.

What is the problem?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum