My previous question has solved my problem, but left me with a lack of understanding.
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');
This test does not pass, which means no ...
doesn't do what I think it does, which includes unimporting the symbols. I've read perldoc no
, but it really seems to be rather unenlightening. Given the results of this code I'd say that it doesn't exactly do what it advertises.
What does no
do? When and why should I be using it?
Using the Parameter Array (@_) Perl lets you pass any number of parameters to a function. The function decides which parameters to use and in what order.
What is the exact difference between :: and -> in Perl? -> sometimes works where :: does not. -> is used for dereferencing; :: is used for referring to other packages.
General Variables$_ - The default input and pattern-searching space. @_ - Within a subroutine the array @_ contains the parameters passed to that subroutine.
no
calls a package's unimport()
, whereas use
calls import()
, both silently skipping the case where no desired sub is found.
However, few packages — indeed, mostly only the pragma modules — support unimport()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With