Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts

    problem with perl modules and cgi script

    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?
    Last edited by dark0s; 02-23-2010 at 08:55 PM.

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    You forgot to declare $self (with the 'my' keyword) before using it.

  • #3
    New Coder
    Join Date
    Jan 2010
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,874
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Please post the code in /usr/lib/perl/5.10/MyModule.pm
    Last edited by FishMonger; 02-23-2010 at 10:58 PM.

  • #5
    New Coder
    Join Date
    Jan 2010
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?
    Last edited by dark0s; 02-23-2010 at 11:54 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •