openkore
关于PERL类的问题(新手)
-----------------这是test.pm----------------------------------------------
#!/usr/bin/perl
package test;
use strict;
use base qw(Exporter);
use encoding 'gbk';
our @EXPORT = qw(test2 test1);
sub new {
my $this = {}; # 创建一个hash指向自己
bless $this; # 把类赋值给引用.
return $this; # 返回引用
}
sub test1 {
my ($weibiao) = @_;
print "test类中的test1被调用:";
print "$weibiao"."/n";
}
sub test2 {
print "test类中的test2被调用:";
print "loveyou111111"."/n";
}
1;
-----------------这是test.pm----------------------------------------------
------------------------------这是调用test.pm的shinian.pl---------------------
#!/usr/bin/perl
BEGIN{ unshift @INC,'e:/perl/xuexi'};
use strict;
use test;
use encoding 'gbk';
my $cup = new test;
$cup->test1("Love");
$cup->test2();
------------------------------这是调用test.pm的shinian.pl---------------------
结果如图:
[attach]257772[/attach]
为什么test1打印出来的是一个地址值??
为什么不带参数的test2可以正常运行?
为什么把test.pm当作模块来用的话,test1("Love");可以正常运行如下:
[attach]257773[/attach]
sotol
[quote]原帖由 [i]openkore[/i] 于 2008-6-19 18:41 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8622514&ptid=1164944][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url]
-----------------这是test.pm----------------------------------------------
#!/usr/bin/perl
package test;
use strict;
use base qw(Exporter);
use encoding 'gbk';
our @EXPORT ... [/quote]
sub new {
my $this = {}; # 创建一个hash指向自己
bless $this; # 把类赋值给引用.
return $this; # 返回引用
}
sub test1 {
my ($weibiao) = @_;
print "test类中的test1被调用:";
print "$weibiao"."/n";
}
$weibiao其实就是指向一个hash的引用
建议看看大骆驼