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

I have a simple module based on tachyon's tutorial:
#!/usr/bin/perl -w # module path: c:/Perl/myperl/CWI/Message.pm package CWI::Message; use strict; use Exporter; use vars qw( $VERSION @ISA @EXPORT ); $VERSION = 1.00; @ISA = qw( Exporter ); @EXPORT = ( &get_msg ); sub get_msg{ return "message from module\n"; } 1;
This script will only work with a full package name (see the comments):
#!/usr/bin/perl -w # script path: c:/Perl/myperl/dev/test_mod.cgi # module path: c:/Perl/myperl/CWI/Message.pm use strict; use lib 'c:/Perl/myperl'; use CWI::Message; # next print statement produces: # 'Name "main::get_msg" used only once' # print get_msg; # prints ok print CWI::Message::get_msg;
Activestate 5.8 and winXP
Thanks in advance, wfsp

Replies are listed 'Best First'.
Re: Using a simple module without full package names
by Joost (Canon) on Jul 12, 2004 at 15:16 UTC
      Many thanks!
      I'd looked at it so long I would never have seen it. I now have to fix the head shaped dent in the wall!
      Again, thanks
        It's good to be able to use Exporter and to understand it but I got bored typing the same old Exporter stuff over and over again, so I wrote Exporter::Easy. It turns
        use Exporter; use vars qw( @ISA @EXPORT ); @ISA = qw( Exporter ); @EXPORT = ( &get_msg );
        into
        use Exporter::Easiest q( EXPORT => &get_msg )
        and lots more.

        Updated: I should point out that it's still Exporter that does the exporting, Exporter::Easy just eliminates the mindless typing involved in setting up @EXPORT, especially if you use tags.