0
我写了Perl module
,在那我用的是class and objects
。 所以我创建了该类的对象并访问它的方法。 例如:为什么我们无法通过::中的对象访问方法perl
{
package sample;
sub Bless
{
my $Class = shift;
my $Name = shift;
bless \$Name, $Class;
}
}
{
package test;
our @ISA = qw(sample);
sub Print
{
my $Name = shift;
print "Hi, I'm $$Name & This is for testing\n";
}
}
my $My_Obj = test->Bless('Ganapathy');
$My_Obj->Print;
对于上述说法,该方案已经正常运行。 当我执行它,它给出了这样的输出,
Hi, I'm Ganapathy & This is for testing
但是,如果我访问使用对象方法与::
这样,
$My_Obj::Print;
它不能正常工作,并抛出类似错误下面,
Useless use of a variable in void context at /home/ganapathy/trainee_2015/perl/inter_perl/chap_13/Object_Doubt.pl line 46.
Name "My_Obj::Print" used only once: possible typo at /home/ganapathy/trainee_2015/perl/inter_perl/chap_13/Object_Doubt.pl line 46.
为什么我不能这样访问,请任何人帮助我。 谢谢。
我只是想检查它为什么不工作? – Ganapathy
@Ganapathy:它*正在工作*。 ' - >'和'::'是非常不同的东西,不可互换。 – Borodin
好的,谢谢你的帮助.... – Ganapathy