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

I'm trying to write a perl module, and cannot export my subs. I'm on Ubuntu 12.04 LTS, using Perl v5.14.2 Here's my module, /home/steve/scripts/lib/STEVE/Test.pm:
package Test; use strict; use warnings; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(test); sub test { print "This is only a drill\n"; } 1;
(yes, now the world knows my file structure). I constructed it according to this post:

http://www.perlmonks.org/?node_id=102347

My driver program, /home/steve/scripts/test.pl, looks like:
#!/usr/bin/perl use lib '/home/steve/scripts/lib'; use STEVE::Test qw(&test); test();
As stated, this fails, with error: Undefined subroutine &main::test called at ./test.pl line 6. Why? I used to write modules all the time (on the same OS, but maybe not the same perl version). Did perl change its export/import/package method? Thanks

Replies are listed 'Best First'.
Re: Problem With Exporting subs from Modules
by choroba (Cardinal) on Nov 29, 2014 at 09:11 UTC
    If you want to use STEVE::Test, you have to name your module accordingly:
    package STEVE::Test; # ^^^^^^^
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Well hell, thank you. I swear this was not the case two years ago, though; was it?

        Oh yes it was! But, you may not have put Test in a subdirectory two years ago. The STEVE:: bit is a path prefix to the the package file name. Perl searches its library path for ./STEVE/Text.pm. I picked up Perl around 2005 (5.8.8) and its been like that since then at least.

        Perl is the programming world's equivalent of English

      Hmm, you don't HAVE to, though it is considered good practice to do so

      Adding import Test 'test'; after the use statement will most likely work equally well