zoukankan      html  css  js  c++  java
  • perl 面向对象 new方法

    [root@wx03 test]# cat Scan.pm 
    package Scan;
    sub new{
        my $class = shift;
        my $self={
                  'a'=>11,
                  'b'=>22,
                   'c'=>33
                 };
        bless $self,$class;
        return $self;
                };
    
    
    sub sum_all {
    
        my $self=shift;
        my ($c,$d,$e)=@_;
         return ($self->{a} + $self->{b} + $self->{c} + $c + $d + $e);
      };
    1;
    [root@wx03 test]# cat t12.pl 
    unshift(@INC,"/root/test");   
    use Scan ;  
    my $ua=Scan->new();
    print $ua->sum_all(1,5,8);
    [root@wx03 test]# perl t12.pl 
    80[root@wx03 test]# 
    
    /*****************new 方法不定义内容:
    
    [root@wx03 test]# cat Scan.pm 
    package Scan;
    sub new{
        my $class = shift;
        my $self={};
        bless $self,$class;
        return $self;
                };
    
    
    sub sum_all {
    
        my $self=shift;
        my ($c,$d,$e)=@_;
         return ( $c + $d + $e);
      };
    1;
    [root@wx03 test]# cat t12.pl 
    unshift(@INC,"/root/test");   
    use Scan ;  
    my $ua=Scan->new();
    print $ua->sum_all(1,5,8);
    [root@wx03 test]# perl t12.pl 
    14[root@wx03 test]# 

  • 相关阅读:
    CSP 训练赛0925
    赛道修建 NOIP 2018
    C
    B
    游戏得分 建立反图SPFA / bellman
    肥宅快乐树 换根+树形DP/dfs
    组合数例题
    龙珠雷达 双指针+DP
    面试-restful规范
    django-中间件
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350530.html
Copyright © 2011-2022 走看看