| [reply] |
No, they both execute the code. perlfunc discusses the difference and generally encourages require over do. Another possibility is to remove the file's entry from %INC so that perl loads the file again, for example:
require 'gash2.pl';
$var = 37; # do some stuff
delete $INC{'gash2.pl'};
require 'gash2.pl';
| [reply] [d/l] |
They both execute the code. But the difference that Corion alerted to is that require includes and compiles the code only once.
So, in the case of the OP, $var was first initialized in env.pl and then given the new value 'default' inside the loop. When env.pl was required the second time nothing happened because it was already loaded, so $var was not affected.
If, instead of a require, a do was issued, env.pl would have been compiled again and $var would be reassigned.
require will look for an entry of the required file on %INC. If found, does nothing.
do ignores %INC and loads the file. Then creates/updates the entry on %INC.
| [reply] |