bharatbsharma has asked for the wisdom of the Perl Monks concerning the following question:

Hello I have directory structure
$HOME/bin $HOME/Upd/Common
I have a package Upd::Common::System (.pm file) in $HOME/Upd/Common where getRemoteProcessIds is defined and in $HOME/bin I have main script given below in . When i run main script i get an error - Undefined subroutine &main::getRemoteProcessIds called at . How to correct?
BEGIN { my $perl_failed = $@; my $HOME = "/home/Z001T7BX"; $ENV{PERL5LIB} .= ":$HOME"; # for child processes push @INC, $HOME; # for this process unless ( grep m{\A${HOME}/bin}, split(":", "$ENV{PATH}") ) { $ENV{PATH} .= ":$HOME/bin"; # for child processes } $ENV{HOME} = $HOME; # for child processes } use Upd::Common::System; my $pid; $pid=getRemoteProcessIds (10.255.22.69, "HUDSON", 4711);

Replies are listed 'Best First'.
Re: ndefined subroutine &main
by perl_lover (Chaplain) on Nov 30, 2010 at 06:33 UTC
    Is getRemoteProcessIds allowed to import by default? Check that in Upd::Common::System module. If it not allowed by default then change your use statement to use Upd::Common::System qw(getRemoteProcessIds);
Re: undefined subroutine &main
by cdarke (Prior) on Nov 30, 2010 at 09:26 UTC
    Upd::Common::System does not appear to be a module from CPAN. Check the documentation for this module, it might not export anything. If the suggestion from perl_lover does not work then try:
    $pid = Upd::Common::System::getRemoteProcessIds (10.255.22.69, "HUDSON +", 4711);
    but really you should read the module's documentation before using it.
      Yes, I have written this perl module . But i believe code in BEGIN of main script should import this module. So i want to find what mistake i am making?

        So, does your module export the routine? You don't show us the relevant parts of your module, so it is hard for us to help you better. Maybe you want to use Exporter in your module?

        package Upd::Common::System; use strict; use Exporter 'import'; # gives you Exporter's import() method directly @EXPORT_OK = qw(getRemoteProcessIds); # symbols to export on request

        ... and in your main program:

        use Upd::Common::System qw( getRemoteProcessIds );
      Thanks a lot . Solution given by is working .
Re: undefined subroutine &main
by locked_user sundialsvc4 (Abbot) on Nov 30, 2010 at 14:27 UTC

    Two pieces of (somewhat lengthy) reading-material will help your understanding very considerably:

    1. perldoc Exporter
    2. perldoc perlmod

    It’s not rocket-science, but a few points are subtle, and these documents are excellent.