Schwern notes that commenting out __END__ can cause surprises if the main body of your module is running under use strict; because now your AutoLoaded subroutines will suddenly find themselves being run under use strict. This is arguably a bug in the current AutoSplit - when it runs at install time to generate the files for AutoLoader to use it doesn't add lines such as use strict; or use warnings; to ensure that the split out subroutines are in the same environment as was current at the __END__ statement. This may be fixed in 5.10.
Elizabeth Mattijsen notes that there are different memory use versus memory shared issues when running under mod_perl, with different optimal solutions depending on whether your apache is forking or threaded.
=pod @ __END__ #!perl -w use strict;
=head1 You don't want to do that
big block of pod
=cut
... 1; __END__
=head1 You want to do this
假如您将您的代码放在 __END__ 后面,那么 perl 分析器就不会去注重它。这能省下一点点 CPU,但是假如你有一块很大的 pod (>4K) ,那它意味着文件的最后磁盘块将不会被读进 RAM 。这也许能获得某些加速。[A helpful heckler observed that modern raid systems may well be reading in 64K chunks, and modern OSes are getting good at read ahead, so not reading a block as a result of =pod @ __END__ may actually be quite rare.]
假如你还是将您的 pod (和测试)放在函数代码的旁边(这看起来更是一种好习惯),那么此建议与您无关。
Exporter 是用 perl 所写的。虽然它很快,但也不是即时的。
许多模块,为了节省您的输入,都默认在您的命名空间内倒出许多函数和符号变量。假如您只有一个参数在 use 后(模块名参数),比如
use POSIX; # Exports all the defaults
于是 POSIX 将有用地在您的命名空间内倒出它的默认符号变量列表。假如您在模块名后有一列表,那它只倒出此列表的符号变量。假如列表为空, 不到处任何符号变量:
use POSIX (); # Exports nothing.
您仍然可以使用所有的函数和其他符号变量 - 但您必须使用它们的全名,如在前面输入 POSIX:: 。许多人说这样实际上让您的代码更干净,而且现在很清楚的知道子程序是在哪定义的。除了这些,它还更快:
评论加载中…
![]() |