开发者

Is this a bug of require of Perl 5.8.8?

Code as follows:

#!/usr/bin/perl

print 1;
{
require shift;                                                                        
}

It turns out that when I run ./script script,two 1s are printed.

So my script file is actually loaded twice? Is this a bug or not??

According to the document:

"require" demands that a library file be included if it hasn开发者_StackOverflow’t already been included.


require only skips loading a file if it was previously loaded with require, use, or do, not for something loaded as the primary script.

See: %INC


No, it's not a bug. Your script prints 1, then requires the name of the first argument, in this case you've supplied the name 'script' which runs your script again printing the second 1.

See Require;

The file must return true as the last statement to indicate successful execution of any initialization code, so it's customary to end such a file with 1; unless you're sure it'll return true otherwise. But it's better just to put the 1; , in case you add more statements.

Also you should see some error, such as Null filename used at script line 5


When I run your code i get:

$ ./script script
Null filename used at script line 5.
Compilation failed in require at ./script line 5.
11$

So I can't reproduce your result... ;)

You're making a false assumption: the fact that your script is called 'script' has nothing to do with it being used, required on done... the require statement is the first time something is required.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜