CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [FishMonger] require won't import at runtime?: Edit Log



g.dave
New User

Nov 11, 2011, 3:56 PM


Views: 2598
Re: [FishMonger] require won't import at runtime?

I've realized my answer.

This works


Code
frobnicate(); 
munge();


as does this

Code
&frobnicate; 
&munge;


Since in the last case the class methods were not imported at compile time, the compiler didn't know how to treat 'frobnicate' and 'munge' as bare words. Declaring them as functions explicitly gives the compiler the clue it needs to execute them as functions at runtime.

syntactically it is akin to a simple lexical declaration of:


Code
foo; # fails 
sub foo { print "foobar!\n" };


which does not work. reversing the order makes it work, or declaring 'foo' as a function also works:

Code
sub foo { print "foobar!\n" }; 
foo; # works!

or

Code
foo(); # works! 
sub foo { print "foobar!\n" };
&bar; # also works!
sub bar { print "barfoo!\n" };


The same principal is involved when using require and then import in a runtime manner. If I think about the timing of compile vs runtime evaluation it begins to make sense why my third example in the original post won't work.

Thanks for the input.


(This post was edited by g.dave on Nov 11, 2011, 3:58 PM)


Edit Log:
Post edited by g.dave (New User) on Nov 11, 2011, 3:58 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives