l.frankline has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Could anyone explain about Exporter, @EXPORT.

I have referred many books but I couldn't understand the use of Exporter, @EXPORT

Is there any differnece between 'use' and 'Exporter' or 'require' and 'Exporter'

Please don't treat this as homework.

Thanks in advance

-Franklin

Don't put off till tomorrow, what you can do today.

Replies are listed 'Best First'.
Re: uses of Exporter, @EXPORT
by ikegami (Patriarch) on Jun 06, 2008 at 05:42 UTC

    use Exporter; is the same as BEGIN { require Exporter; Exporter->import(); }

    Please don't treat this as homework.

    Maybe you should treat this as homework.

    use
    require
    Exporter

    It's not that I don't want to help you, it's that your question is awfully vague.

      Thanks for the info...

      Don't put off till tomorrow, what you can do today.

      Ing for your have
Re: uses of Exporter, @EXPORT
by leocharre (Priest) on Jun 06, 2008 at 15:47 UTC

    @EXPORT means that stuff will be force fed to the caller (where you say use Apples)- means the calling script/package will be injected, its namespace raped and pillaged, with whatever you have in @EXPORT.

    You want @EXPORT_OK, which lists what your caller *may* at its choosing, take bites of- import into its namespace.

    require is runtime, use is compile time.

    If in the middle of your code (say, line 50) you have require Apples; and Apples is not present or found on the system, you don't get an error until you get to line 50.

    In addition to that, you don't load Apples until line 50. So, if you have an intense operation involving multiple modules and code, you may want to (for performance sake) load modules as they are needed (with require). This is not usually necessary. Personally I've been doing it a lot.

    If in line 50 we had use Cwd; instead of require Cwd, then as soon as you run your program, we check for and load Cwd, at compile time. If you don't have it your program fails, immediately. Also, every use statement in your code goes through the same thing. This is useful to check for errors or missing deps before your program runs.

    This stuff is basic-ish- but there are odd abstract snags and peculiarities- have you tried reading perdoc and cpan? It might be weird at first but it helps a lot.