This causes error right after you start your program. Because use forced a require in the BEGIN block, which is executed before the if checking.if (1 == 2) { use foo; }
You will get an error, but it is about the uninitialized variable $a, not whether foo.pl exists. So things happen in the visually expected sequence.if ($a == 2) { require "foo.pl"; }
This will cause a warning about the require syntax, but not the existance of foo.pl. That happens right after you start the program, as the first thing Perl will do, is checking syntax, but not whether the module exists (next example shows this more clearly)while (1) {} require foo.pl;
This time, the syntax error is removed. It does not cause any error saying the module is not there, which means Perl will only try to load foo.pl at the time when it is really needed, which will never happen, because of the deadloop before the require.while (1) {} require "foo.pl";
In reply to Re: what's faster: use or require
by pg
in thread what's faster: use or require
by dreamy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |