in reply to Re: Export function from module
in thread Export function from module

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

Replies are listed 'Best First'.
Re^3: Export function from module
by davido (Cardinal) on Apr 30, 2013 at 04:43 UTC

    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

Re^3: Export function from module
by 2teez (Vicar) on Apr 30, 2013 at 04:56 UTC

    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