in reply to Re^2: Undefined subroutine &main::func1
in thread Undefined subroutine &main::func1 [SOLVED]

Hello afoken,

Thank you for your time and effort reading and replying to my query.

Well after a lot of experimentation I have concluded that the problem lies with the directories. I am using Net::SNTP::Client.pm which I have install it locally. I assume since the moment that I install it locally since then any modification I am applying on the module is ignored because I can see the installed directory Net-SNTP-Client.

So I assume that I first need to uninstall the module and then find a way to experiment with the module before installing it.

I have tried almost 100 different combinations with the use lib '/home/username/ModuleFolder/'; but I keep getting the same error:

Can't locate Net/SNTP/Client.pm in @INC (you may need to install the N +et::SNTP::Client module) (@INC contains: /home/tinyos/Desktop/Test /h +ome/tinyos/Desktop/Test/ /etc/perl /usr/local/lib/perl/5.18.2 /usr/lo +cal/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5 +.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at client.pl lin +e 8. BEGIN failed--compilation aborted at client.pl line 8.

I have unistalled my module since I think this is the root of all problems before I move to the next step I need to find a way to make it work.

Sample of Module Net::SNTP::Client.pm:

#!/usr/bin/perl use strict; use warnings; use Exporter; package Net::SNTP::Client; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(func1 func2); %EXPORT_TAGS = ( DEFAULT => [qw(&func1)], Both => [qw(&func1 &func2)] ); sub func1 { return reverse @_ } sub func2 { return map{ uc }@_ } 1;

Sample of code for script client.pl:

#!/usr/bin/perl use strict; use warnings; my @list = qw (J u s t ~ A n o t h e r ~ P e r l ~ H a c k e r !); use lib '/home/username/Desktop/Test'; use Net::SNTP::Client qw(func1); print func1(@list),"\n";
Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^4: Undefined subroutine &main::func1
by soonix (Chancellor) on Jun 28, 2015 at 16:37 UTC
    • the module names in use and package statement must match exactly (speeling and cAsE) - seems OK in your post
    • the file must be in a subdirectory of one of the @INC directories - find out with the following code:
      use strict; use warnings; my $module = 'Net::SNTP::Client'; # change module name here if necessa +ry (my $file = $module) =~ s!::!/!g ; $file .= '.pm'; print "looking for $file\n"; my $found = 0; for (@INC) { my $look = "$_/$file"; if (-e $look) { print "Hooray! found it: $look\n"; ++$found; } else { print "NOT found: $look\n" } } print "PROBLEM: found $found files instead of 1 (one)\n" if $found != +1;
    • And your sub func1 definition should be within the scope of the package statement (looks OK in your post)
    Update: Ah, you just found it out while I was composing this node :-)