in reply to Re^2: Autovivification with require
in thread Autovivification with require
I believe what that usage is trying to highlight is that if you have a bareword use Foo::Bar; or require Foo::Bar; then at compile time perl knows that there is a Foo::Bar package and that it will make some kind of entries in the package stash (*Foo::Bar and/or %Foo::Bar::) before continuing to compile subsequent code (which may affect things like "variable only used once" warnings). Also in the use case the import method would be called at compile time which would then have side effects (e.g. inserting entries in the calling package's namespace).
If you use the string version the code in the file pulled in won't be compiled until the require statement is actually executed which will be after everything else has already compiled. It affects when some things happen; whether that's an "advantage" or not depends on what you're expecting to happen.
## Poor example: Cwd pulled in with use so %Cwd:: is fully populated $ perl -E 'say qq{Cwd stash keys: }, scalar %Cwd::; use Cwd; say qq{Cw +d stash keys after use: }, scalar %Cwd::; say qq{Config stash keys: } +, scalar %Config::;require "Config.pm"; say qq{Config stash keys afte +r requiire: }, scalar %Config::;' Cwd stash keys: 39 Cwd stash keys after use: 39 Config stash keys: 1 Config stash keys after requiire: 20
The cake is a lie.
The cake is a lie.
The cake is a lie.
|
|---|