kaiser_cn 发表于 2015-12-28 13:49:13

perl类定义必须返回真值

package Logger ;
use strict ;
sub new
{
    my $class = shift() ;
    my $self = {} ;
    bless $self, $class ;
    return $self ;
}
sub message
{
    shift ;
    my ($msg, $color) = @_ ;
    print "@: @_ \n" ;
    my $cmd = "echo -e \033[40;$color$msg\033[0m" ; # this does not work on windows, try it on unix/linux
    print "cmd: $cmd\n" ;
    `cmd` ;
    #print "$msg\n" ;
}
sub info
{
    my ($self, $msg) = @_ ;
    my $color = "37m" ; # white
    $self->message($msg) ;
}
sub warning
{
    my ($slef, $msg) = @_ ;
    my $color = "33m" ; # yellow
    $self->message($msg, $color) ;
}
sub error
{
    my ($self, $msg) = @_ ;
    my $color = "31m" ; # red
    $self->message($msg, $color) ;
}
1 ; #这个1就是类的返回值,不可省略
页: [1]
查看完整版本: perl类定义必须返回真值