zoukankan      html  css  js  c++  java
  • perl bless例子

    jrhdpt02:/root/big# cat a1.pl 
    unshift(@INC,"/root/big2");
    require RegularEmployee;
    use Data::Dumper;
    $var=RegularEmployee::new(a,b,c,d);
     my $xx= Dumper($var);  
    print $xx;  
    print "
    ";
    jrhdpt02:/root/big# perl a1.pl 
    $VAR1 = bless( {
                     'months_worked' => 0,
                     'monthly_salary' => 'd',
                     'position' => 'c',
                     'name' => 'a',
                     'age' => 'b'
                   }, 'RegularEmployee' );
    
    
    
    没有bless呢?
    jrhdpt02:/root/big# cat RegularEmployee.pm 
    package RegularEmployee;
    sub new {
     my ($name,$age,$starting_position,$monthly_salary)=@_;
     my $r_employee = {
     "name" =>$name,
     "age" =>$age,
     "position" => $starting_position,
     "monthly_salary" => $monthly_salary,
     "months_worked" =>0,
    };
     #bless $r_employee,'RegularEmployee';
     return $r_employee;  ##返回对象的引用
    }
    sub promote{
       #...
       }
    1;
    jrhdpt02:/root/big# cat a1.pl 
    unshift(@INC,"/root/big2");
    require RegularEmployee;
    use Data::Dumper;
    $var=RegularEmployee::new(a,b,c,d);
     my $xx= Dumper($var);  
    print $xx;  
    print "
    ";
    jrhdpt02:/root/big# perl a1.pl 
    $VAR1 = {
              'months_worked' => 0,
              'monthly_salary' => 'd',
              'position' => 'c',
              'name' => 'a',
              'age' => 'b'
            };

  • 相关阅读:
    I/O性能优化
    磁盘性能指标
    磁盘I/O工作原理
    文件系统工作原理
    Linux命令行工具之free命令
    内存性能优化
    内存工作原理
    内存中的Buffer和Cache的区别
    proc文件系统
    oracle 查询 LOB 字段大小
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351104.html
Copyright © 2011-2022 走看看