in reply to Re: Can I retry "use" when module load fails?
in thread Can I retry "use" when module load fail ?

Thanks answering!! However I ran in another problem, simplified as follow. Say that I have a module CommonPiece
package CommonPiece; require Exporter; our @ISA =qw/Exporter/; our @EXPORT =qw/htmlStyle/; sub htmlStyle { print "<style>...</style>"; } 1; __END__

Now in main

use CommonPiece; htmlStyle; # this works
However, if I change to :
BEGIN { require CommonPiece; } htmlStyle; #Undefined subroutine &main::htmlStyle called at /...path/

What did I missed?

Replies are listed 'Best First'.
Re^3: Can I retry "use" when module load fails?
by NetWallah (Canon) on Apr 15, 2013 at 05:42 UTC
    You missed the "import" part noted in Athanasius's post.

                 "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
            -- Dr. Cox, Scrubs

      I noticed... but why? I have nothing to do with import. I already used Exporter to export my stuffs. so if use is identical to BEGIN {require...}, then that should be no problem sub import{} never existed in my module, and then I won't call it. What's the difference?
        Actually, you DO need to call the "import" method, in order to inject the "exported" methods and variables into your (main) namespace.

        Exporter documentation explains this :

        The Exporter module implements an import method which allows a module to export functions and variables to its users' namespaces.

                     "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
                -- Dr. Cox, Scrubs