in reply to Undefined subroutine &main::func1 [SOLVED]

Hi thanos1983
Just before you go to bed, take a second look at this (Just for the fun of it! Nothing serious):

pm code

package Hommy; use warnings; use strict; use Exporter qw(import); our @EXPORT_OK = qw(teller); sub teller(\[$@%]); sub teller(\[$@%]) { my $in = shift; my $data = { SCALAR => sub { print join $/ => split // => ${ $_[0] } }, ARRAY => sub { print join $/ => @{ $_[0] } }, HASH => sub { for my $k ( sort keys $_[0] ) { print $k, join $/ => split // => $_[0]{$k}; } }, }; $data->{ ref $in }->($in); } 1;

Then the pl script to use the pm

use warnings; use strict; use lib '.'; # note here use Hommy qw(teller); teller @{[(split//=>"home sweet home!")]};
You really, don't need to install your own module atleast you can manipulate the @INC at compile time. Check the note!

Replies are listed 'Best First'.
Re^2: Undefined subroutine &main::func1
by thanos1983 (Parson) on Jun 28, 2015 at 14:20 UTC

    Hello Anonymous,

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

    I assume the same, in theory I should install the module in order to be able to use it but before I reach this point to post this question Undefined subroutine &main I was not able to execute my code. See question How to create a reusable module with Exporter SOLVED, I still can not find a way to use new modules with the name eg. Net::SNTP::Something without installing them locally. I keep getting the same error if I do not install them:

    Can't locate Net/SNTP/Server.pm in @INC (you may need to install the N +et::SNTP::Server module) (@INC contains: . /etc/perl /usr/local/lib/p +erl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/per +l5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl) +at server.pl line 8. BEGIN failed--compilation aborted at server.pl line 8.

    For example, I have another module that I want to use named Net::SNTP::Server.pm. For simplicity and demonstration purposes I am using the same code from Net::SNTP::Client.pm with only difference the package name. Sample of code provided bellow:

    #!/usr/bin/perl use strict; use warnings; use Exporter; package Net::SNTP::Server; 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;

    I am calling it from the server.pl script. Sample of code provided under:

    #!/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 '.'; # note here use Net::SNTP::Server qw(&func1); print func1(@list),"\n";

    The error that I am getting is the same:

    Can't locate Net/SNTP/Server.pm in @INC (you may need to install the N +et::SNTP::Server module) (@INC contains: . /etc/perl /usr/local/lib/p +erl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/per +l5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl) +at server.pl line 8. BEGIN failed--compilation aborted at server.pl line 8.

    So at this point you will say that I am not using correctly the directories. I can not call a module Net::SNTP::Server.pm without installing it on the lib directory, can I?

    Thank you for your time and effort.

    Seeking for Perl wisdom...on the process of learning...not there...yet!