in reply to Subroutines not exporting? Why?

I suspect you are using __END__where what you really meant was exit;.

  1. First perlhas to read your script file and produce the under-the-covers code it will execute; this is sometimes called "compilation" and sometimes "interpretation" (the latter is more technically correct);
  2. Then perlhas to execute the code it created during the interpretation phase.

So these two keywords have different functions:

Thus, your __END__is causing perlto stop reading the source code before it gets to the subroutine; the subroutine is therefore never compiled. During execution, it does not exist, hence the error.

So, if I'm guessing right about your intentions, the fix is fairly simple, as noted by everyone else on this thread:

package My::Util; use strict; use warnings; use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw( get_file_name ); exit; sub get_file_name { ... } 1; __END__

Replies are listed 'Best First'.
Re^2: Subroutines not exporting? Why?
by Anonymous Monk on Jul 07, 2015 at 10:41 UTC
    this is sometimes called ... "interpretation" (... more technically correct) ... the interpretation phase

    I don't recall the Perl documentation or the Camel ever referring to it as that... perhaps you meant "parsing"?

    Although the existence of eval and BEGIN really blur the lines, if we're going to be picky about the compilation/runtime phases, then in fact the exit you suggest would be executed during the compilation phase of the main script, causing the rest of the main script after the use to never even be compiled!

    Also, it sounds like you're saying that "everyone else on this thread" suggested exit?

      I don't recall the Perl documentation or the Camel ever referring to it as that... perhaps you meant "parsing"?

      You may translate it that way if you wish. My reference was not Perl-specific. The difference between a compiler and an interpreter is that the compiler converts source code to object code and then its job is done; the interpretter reads the source code and performs the tasks. The exact process used varies by implementation.

      Although the existence of eval and BEGIN really blur the lines

      An interesting observation.

      Also, it sounds like you're saying that "everyone else on this thread" suggested exit?

      I can see where one might draw that inference, but only if they choose to ignore the preponderence of evidence that up to that point in time everyone had, in fact, discussed __END__, not exit. Most reasonable people would not likely jump to the conclusion that exitwas the reference being made.

      Clarification and precision is useful in our profression, to be sure; though the latter is less necessary in general conversation, it pays to be careful. Thank you for the notes.

        My reference was not Perl-specific.

        Yeah, it took me a while to wrap my head around Perl's compilation / runtime phases, too. One thing in particular that seems to throw people off sometimes is that use is essentially like an eval inside of a BEGIN. I recommend this reading because that's what helped me understand: BEGIN, UNITCHECK, CHECK, INIT and END in perlmod, and in this order: use, require, do, and eval.