11
我的previous question已經解決了我的問題,但讓我缺乏理解。在Perl中關鍵字`no`實際上做了什麼?
use 5.014;
use warnings;
use Test::More;
# still has carp after no Carp
package Test0 {
use Carp qw(carp);
sub new {
my $class = shift;
my $self = {};
carp 'good';
bless $self, $class;
return $self;
}
no Carp;
}
my $t0 = Test0->new;
ok(! $t0->can('carp'), 'cannot carp');
這個測試沒有通過,這意味着no ...
沒有做什麼,我想這樣做,其中包括unimporting的符號。我讀過perldoc no
,但它確實看起來很沒有說服力。鑑於此代碼的結果,我會說它並不完全按照它的廣告。
no
是做什麼用的?何時以及爲什麼我應該使用它?
有人可能會爭辯說,'出口商'沒有定義'unimport'來與其「進口」一起是一個錯誤。 – geekosaur 2012-04-25 18:40:58
@geekosaur,我同意。 (可以爭辯:)) – pilcrow 2012-04-25 18:41:46