perl oo编程如何调用方法?
时间:2010-08-02
来源:互联网
oo.pl
#!/usr/bin/perl -w
use strict;
use time2;
main()
{
my $time=new time2("statime"
;
print $time->getstatime();
}
&main();
-------------------------------------------------------------
time2.pm
#!/usr/bin/perl -w
use strict;
package time2;
sub new()
{
my $class=shift;
my $self={
statime=>undef,
notime=>undef};
bless $self,$class;
return $self;
}
sub getstatime()
{
my $self=shift;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time());
$sec=($sec<10)?"0$sec"
sec;
$min=($min<10)?"0$min"
min;
$hour=($hour<10)?"0$hour"
hour;
$mday=($mday<10)?"0$mday"
mday;
$mon=($mon<9)?"0".($mon+1)
$mon+1);
$year+=1900;
$self->{"statime"}="[$year-$mon-$mday $hour
min
sec]";
return $self->{statime};
}
sub getnontime()
{
my $self=shift;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time());
$sec=($sec<10)?"0$sec"
sec;
$min=($min<10)?"0$min"
min;
$hour=($hour<10)?"0$hour"
hour;
$mday=($mday<10)?"0$mday"
mday;
$mon=($mon<9)?"0".($mon+1)
$mon+1);
$year+=1900;
$self->{"notime"}="[$year-$mon-$mday\_$hour\_$min\_$sec]";
return $self->{notime};
}
[root@back liuqing]# ./oo.pl
time2.pm did not return a true value at ./oo.pl line 3.
BEGIN failed--compilation aborted at ./oo.pl line 3.
刚学perl,不知道该如何调用time2.pm(time2这个类写的应该有问题)里面的getstatime()的方法?望大牛们帮帮忙!
#!/usr/bin/perl -w
use strict;
use time2;
main()
{
my $time=new time2("statime"

print $time->getstatime();
}
&main();
-------------------------------------------------------------
time2.pm
#!/usr/bin/perl -w
use strict;
package time2;
sub new()
{
my $class=shift;
my $self={
statime=>undef,
notime=>undef};
bless $self,$class;
return $self;
}
sub getstatime()
{
my $self=shift;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time());
$sec=($sec<10)?"0$sec"

$min=($min<10)?"0$min"

$hour=($hour<10)?"0$hour"

$mday=($mday<10)?"0$mday"

$mon=($mon<9)?"0".($mon+1)

$year+=1900;
$self->{"statime"}="[$year-$mon-$mday $hour


return $self->{statime};
}
sub getnontime()
{
my $self=shift;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time());
$sec=($sec<10)?"0$sec"

$min=($min<10)?"0$min"

$hour=($hour<10)?"0$hour"

$mday=($mday<10)?"0$mday"

$mon=($mon<9)?"0".($mon+1)

$year+=1900;
$self->{"notime"}="[$year-$mon-$mday\_$hour\_$min\_$sec]";
return $self->{notime};
}
[root@back liuqing]# ./oo.pl
time2.pm did not return a true value at ./oo.pl line 3.
BEGIN failed--compilation aborted at ./oo.pl line 3.
刚学perl,不知道该如何调用time2.pm(time2这个类写的应该有问题)里面的getstatime()的方法?望大牛们帮帮忙!
作者: leoxqing 发布时间: 2010-08-02
use package
作者: Wayne_sama 发布时间: 2010-08-02
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28