in reply to Export function from module

The first line of HELPER.pm says: package Helper.

The 5th line of test.pl is use HELPER;

Though your filesystem may or may not be case-sensitive, package names are identifiers, and Perl's identifiers are case sensitive. You should be consistent in your use of case. I recommend naming the module Helper.pm, the package, Helper, and then "use Helper;". But if you prefer all caps, make sure your package name is all caps too.


Dave

Replies are listed 'Best First'.
Re^2: Export function from module
by Anonymous Monk on Apr 30, 2013 at 03:39 UTC
    Thanks for the reply Dave... That did the trick, but now I am confused. I though the use HELPER, simply imports packages from a file. Then by my exporting the functions I wish to be available, I simply need to call the function and the functions exported in the package are available to the calling script. What part am I missing? thanks

      use HELPER;: Perl looks for a file named HELPER.pm from among the paths listed in @INC, and it is found. But use HELPER; is the same as saying:

      BEGIN{ require HELPER; HELPER->import(); }

      The problem is that second part; you have inherited Exporter into a package named Helper. So when Perl goes looking for HELPER->import() it doesn't find anything. And what does exist, Helper->import() isn't being called, because you're using HELPER, not Helper.

      You may as well be saying:

      BEGIN { require HELPER; Goofy->import(); }

      Additonally, the fully qualified name of foo() isn't HELPER::foo, it's Helper::foo.


      Dave

      Hi AM,
      I want to believe the Anonymous Monk is the OP iang.
      If so, what other errors are you getting?
      Dave have pointed out that explicitly, that the package you used is Helper not HELPER.
      Hope, your module is also saved as Helper.pm not HELPER.pm.

      That been said, don't forget you only "exported" the foo subroutine.
      However, if you still wanted the bar subroutine, then use Helper::bar() in your script.

      UPDATE: Oouch!! Davido, got that answered before me !!! Why am i this slow typing..Ah...
      Nice one, faster fingers.

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me