in reply to cgi and own modules causing unspecified error

Have you looked at your web server error log? It has more information.

In which directory does Hello.pm live?

The current directory of your program when it is run from your web server is not what you think it is.

The easiest approach is to tell Perl where to find its files:

use lib 'c:/users/amitsq/whatever/path/to/own/modules';

Replies are listed 'Best First'.
Re^2: cgi and own modules causing unspecified error
by amitsq (Beadle) on Jun 08, 2017 at 14:30 UTC

    yes that's it. Expanding my example now, i get another error "Can't locate object method "new" via package "Hello" (perhaps you forgot to load "Hello"?)"


    thats the new code:
    Hello-2.pl
    #!d:\perl\bin\perl.exe use lib 'S:\incubator\ex\Hello.pm'; print"Content-type:text/html;charset=UTF-8\n\n" ; my $obj = Hello->new( sample_data => 'hello world', more_data => 'blah blah blah' ); $obj->sample_method();
    Hello.pm
    #!d:\perl\bin\perl.exe package Hello; #SampleObject; sub new { my ($class, %args) = @_; return bless { %args }, $class; } sub sample_method { my ($self) = @_; print $self->{sample_data}; } 1;

      Hey amitsq, the following is incorrect:

      use lib 'S:\incubator\ex\Hello.pm';

      You add the *path* to the use lib pragma, not the file:

      use lib 'S:\incubator\ex';

        And add use Hello; :)

        changed it, but it just looks worse since the error is again : The page cannot be displayed because an internal server error has occurred.
        current code in hello-2.pl:
        #!d:\perl\bin\perl.exe use lib 'S:\incubator\ex'; use Hello; print"Content-type:text/html;charset=UTF-8\n\n" ; my $obj = Hello->new( sample_data => 'hello world', more_data => 'blah blah blah' ); $obj->sample_method();
      use lib 'S:\incubator\ex\Hello.pm';

      Add the directory in which modules reside, rather than the full path to the module. Also you still need to use it:

      use strict; use warnings; use lib '/home/marto/temp'; use Hello; my $obj = Hello->new( sample_data => 'hello world', more_data => 'blah blah blah' ); $obj->sample_method();

      Also: lib.

      Can't locate object method "new" via package "Hello" (perhaps you forgot to load "Hello"?)

      The hint is right - you did forget to load "Hello". See use.

        adding the line  use "Hello" leads again to the error " The page cannot be displayed because an internal server error has occurred."