in reply to Re^6: Using import to generate subroutines
in thread Using import to generate subroutines
The point being that, for example this code
is not compiled down to a series of ops likeprint $$f; { no strict 'refs'; print $$f; print $$g; } print $$f;
print $$f; switch on the strict refs flag; print $$f; print $$g; switch off the strict refs flag; print $$f;
Every dereference op has a flag on it to say whether it should be strict or not so it is in fact compiled down to something like
print ( dereference $f allowing strings ); print ( dereference $f not allowing strings ); print ( dereference $g not allowing strings ); print ( dereference $f allowing strings );
The no strict 'refs' does not perform any action at all at run time and so it's position relative to loops is irrelevant.
Also, every time you say use ... you run the module's import() method. It happens at compile time but it certainly isn't a once-only thing.I'm not sure what your point is, I think you have misintepreted
any use statement only gets run once no matter where it is
All I meant by this was
use MyModule; # this will be run once at compile time print "hello\n"; use MyModule; # this will be run once at compile time for (1..10) { use MyModule; # this will be run once at compile time print $_; }
Each of the 3 use statements are run once only. If they were require statements then the 3rd one would be run 10 times because when you're dealing with require it does matter where it is.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Using import to generate subroutines
by diotalevi (Canon) on Nov 25, 2004 at 00:24 UTC |