Perl - 第四篇
时间:2007-02-22 来源:penny_kan
open(INFILE, "input.txt") or die "Can't open input.txt: $!"; |
my $line = <INFILE>; |
while (<INFILE>) { |
1、用法:use Module VERSION LIST (D:\manual\perl\perldoc-html\functions\use.html)
use Module VERSION or use Module LIST or use Module or use VERSION |
Is equivelant to
BEGIN { require Module; import Module LIST; } |
1/ Do not export method names!
2/ Do not export anything else by default without a good reason!
*Exports pollute the namespace of the module user. 如果必需export操作,最好用@EXPORT_OK代替@EXPORT,并且避免使用短的或常用的符号以防命名冲突。 * 事实上不export仍然可以访问module 中的内容,使用方法ModuleName::item_name (or $blessed_ref->method) 3、import: import用法见use
- use ModuleName;
This imports all the symbols from ModuleName's @EXPORT into the namespace of the use statement.
- use ModuleName ();
This causes perl to load your module but does not import any symbols.
- use ModuleName qw(...); [从前面的export看来,这类import方法最可取,不明白]
This imports only the symbols listed by the caller into their namespace. All listed symbols must be in your @EXPORT or @EXPORT_OK, else an error occurs. The advanced export features of Exporter are accessed like this, but with list entries that are syntactically distinct from symbol names.