下面perl代码中的bless {_temperature => shift} => $class;语句如何理解!

#!perl -w
use SOAP::Transport::HTTP;
SOAP::Transport::HTTP::CGI
    -> dispatch_to('Temperatures')
    -> handle;
package Temperatures;
sub f2c {
      my ($class, $f) = @_;
      return 5/9*($f-32);
  }
sub c2f {
      my ($class, $c) = @_;
      return 32+$c*9/5;
  }
sub new {
      my $self = shift;
      my $class = ref($self) || $self;
      bless {_temperature => shift} => $class;
  }
sub as_fahrenheit {
      return shift->{_temperature};
  }
sub as_celsius {
      return 5/9*(shift->{_temperature}-32);
  }
阅读 2.8k
2 个回答

bless {_temperature => shift} => $class;

bless {_temperature => shift}, $class;
是一个意思

恩,那这里为什么可以把哈西{_temperature => shift},bless给自身的引用$class,平时不是都是bless ($self, $class) 这样使用的吗,这两者有什么区别???

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进