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就是类的返回值,不可省略

posted on 2011-07-31 23:02  perlman  阅读(670)  评论(0编辑  收藏  举报

导航