• 数组的数组 散列的散列


    <pre name="code" class="sql"><pre name="code" class="sql"><pre name="code" class="sql">数组的数组:
    
    
    
    数组的数组的引用:  [] 表示数组的引用:
    
    [root@dr-mysql01 ~]# cat t1.pl 
    @matrix=([1,2,3],[4,5,6],[7,8,9]);
    
    print $matrix[2][0];
    print "
    ";
    print $matrix[1][1];
    
    You have mail in /var/spool/mail/root
    [root@dr-mysql01 ~]# perl t1.pl 
    7
    5[root@dr-mysql01 ~]# 
    
    
    #一个指向“包含有数组引用的数组”的引用
     
    
    jrhxpt01:/root# cat 1.pl 
      $ref_to_AoA = [
                [ "fred", "barney", "pebbles", "bambam", "dino", ],
                [ "homer", "bart", "marge", "maggie", ],
                [ "george", "jane", "elroy", "judy", ],
            ];
            print $ref_to_AoA[2][2];
            print "
    ";
            print $ref_to_AoA->[2][2];
            print "
    ";
            print $ref_to_AoA->[2]->[2];
            print "
    ";
    jrhxpt01:/root# perl 1.pl
    
    
    elroy
    elroy
    
    
    散列的散列的引用:{}表示hash的引用:
    
    jrhxpt01:/root# cat 2.pl 
    %HOH = ( flintstones => { husband =>  "fred", pal => "barney", }, jetsons => { husband => "george", wife =>"jane", "his boy" => "elroy", }, simpsons => { husband => "homer", wife => "marge", kid => "bart" } );
    print $HOH{flintstones}->{husband};
    print "
    ";
    print $HOH{flintstones}{husband};
    print "
    ";
    print $HOH{jetsons}->{wife};
    print "
    ";
    print $HOH{jetsons}{wife};
    print "
    ";
    jrhxpt01:/root# perl 2.pl 
    fred
    fred
    jane
    jane
    
    
    散列的散列:
    
    [root@dr-mysql01 ~]# cat ip.pl 
    use Encode;
    use Encode::CN;
    use JSON; 
    use URI::Escape;
    use LWP::Simple;
    print "hostip is $_
    ";	
    $host = "http://ip.taobao.com/service/getIpInfo.php?ip=$ARGV[0]";
    $content = get($host);
    ;
    print "$content
    ";
    $perl_scalar = decode_json($content);
    $var=$perl_scalar->{data}->{ip};
    print $var
    
    [root@dr-mysql01 ~]# perl ip.pl 202.101.172.35
    hostip is 
    {"code":0,"data":{"country":"u4e2du56fd","country_id":"CN","area":"u534eu4e1c","area_id":"300000","region":"u6d59u6c5fu7701","region_id":"330000","city":"u676du5ddeu5e02","city_id":"330100","county":"","county_id":"-1","isp":"u7535u4fe1","isp_id":"100017","ip":"202.101.172.35"}}
    
    [root@dr-mysql01 ~]# cat t8.pl
    use Encode;
    use Encode::CN;
    use JSON; 
    use URI::Escape;
    use LWP::Simple;
    print "hostip is $_
    ";	
    $host = "http://ip.taobao.com/service/getIpInfo.php?ip=$ARGV[0]";
    $content = get($host);
    ;
    $perl_scalar = decode_json($content);
    $var=$perl_scalar{data}->{ip};
    print $var;
    print "
    ";
    [root@dr-mysql01 ~]# perl t8.pl 202.101.172.35
    hostip is 
    
    
    [root@dr-mysql01 ~]# 
    
    
    
    
    [root@dr-mysql01 ~]# cat t8.pl 
    use Encode;
    use Encode::CN;
    use JSON; 
    use URI::Escape;
    use LWP::Simple;
    print "hostip is $_
    ";	
    $host = "http://ip.taobao.com/service/getIpInfo.php?ip=$ARGV[0]";
    $content = get($host);
    ;
    $perl_scalar = decode_json($content);
    $var=$perl_scalar{data}{ip};
    print $var;
    print "
    ";
    [root@dr-mysql01 ~]# perl t8.pl 202.101.172.35
    hostip is 
    


    
    
    
    
    
                                        
    
  • 相关阅读:
    Streaming+Sparksql使用sql实时分析 rabbitmq+mongodb+hive
    几种指定链接库搜索路径
    配置ssh
    无交换机情况下的集群互联
    请找出至少一个由递推关系 a(i) = a(i – 1) + a(i – 2) 生成的数列,使得当 n 趋于 (√5+1)/2的数列
    hdu 4027 Can you answer these queries?
    hdu 4022 Bombing
    hdu 4034
    hiho 第七周 完全背包
    hiho 第六周 01背包
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351135.html
Copyright © 2020-2023  润新知