I have some module, and want to make alias for some sub. Here is the code:
#!/usr/bin/perl
package MySub;
use strict;
use warnings;
sub new {
my $class = shift;
my $params = shift;
my $self = {};
bless( $self, $class );
return $self;
}
sub do_some {
my $self = shift;
print "Do something!";
return 1;
}
*other = \&do_some;
1;
It works, but it produces a compile warning
Name "MySub::other" used only once: possible typo at /tmp/MySub.pm line 23.
I know that I can just type no warnings 'once';
, but is this the only solution? Why is Perl warning me? What am I doing wrong?
{
no warnings 'once';
*other = \&do_some;
}
or
*other if 0; # Prevent spurious warning
*other = \&do_some;
I prefer the latter. For starters, it will only disable the instance of the warning you wish to disable. Also, if you remove one of the lines and forget to remove the other, the other will start warning. Perfect!