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

Hello Everyone, I am new to perl as well as to this community. I use eclipse editor to write perl script. I have idea, how a module can be written in OO way and how to use it but i am facing challenges when i am writting the same module and want to use Exporter module to import functions.While execution I get error "Can't continue after import errors in eclipse editor but it get executed. If you try same script to execute at windows command prompt then it throws error."

#Test.pm package Test; use strict; use Exporter; 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;
#Test.pl use strict; use warnings; # you may need to set @INC here (see below) my @list = qw (J u s t ~ A n o t h e r ~ P e r l ~ H a c k e r !); # case 1 use Test; print func1(@list),"\n"; print func2(@list),"\n"; # case 2 use Test qw(&func1); print func1(@list),"\n"; print Test::func2(@list),"\n"; # case 3 use Test qw(:DEFAULT); print func1(@list),"\n"; print func2(@list),"\n"; # case 4 use Test qw(:Both); print func1(@list),"\n"; print func2(@list),"\n";
Thank you!

Replies are listed 'Best First'.
Re: Can't continue after import errors
by toolic (Bishop) on Jun 12, 2015 at 19:45 UTC
    "Test" is an unfortunate name for your module because it collides with the Test module already installed on your system. Your code is likely ignoring your Test module. Prove this to yourself with this code:
    use Data::Dumper; print Dumper(\%INC);

    Rename your package as Test2, your file as Test2.pm, and:

    use Test2 qw(&func1); # etc.
Re: Can't continue after import errors
by marinersk (Priest) on Jun 12, 2015 at 19:42 UTC

    Don't call it Test.
    (It is generally a bad idea to use names that are highly likely to have already been used, or might be in the native language itself, and "Test" is far too likely a candidate to have even considered using the name.)  :-)

    Change the filename and all references to name to SantoTest.

    Also remember to use SantoTest;in Test.pl.

Re: Can't continue after import errors
by AnomalousMonk (Archbishop) on Jun 12, 2015 at 21:27 UTC
    Don't call it Test ...
    "Test" ... collides with the Test module ...

    Also be aware that in a "case preserving but case insensitive" file system like that used in Windose (gotta love the 'Dose), the possibilities for collision are increased. (I don't know how this works on *nix-ish systems.) I found this out the hard way when I tried to define a Base.pm module to play around with DNA base pairs and discovered, after much puzzlement, that it collided with the base pragma!


    Give a man a fish:  <%-(-(-(-<

      Thanks Everyone.....It works.