My Opera is closing 1st of March

simple

Subscribe to RSS feed

我的perl学习笔记,列表和数组

  1. 列表的定义。列表是一组标量组成的序列,被括号括起来
    (1, 5.3, "hello", 2)
    

    ()为空列表.
    列表中也可包含变量
    (17, $var, "a string")
    

    也可包含表达式
    (17, 26 << 2)
    ($value, "The answer is $value")
    
  2. 在数组中存储列表
    @array = (1, 2, 3);
    
  3. 访问数组中的元素
    @array = (1, 2, 3, 4);
    给其中的一个元素赋值
    $array[3] = 5;
    (1, 2, 3, 5)
    
  4. 使用数据区域
    (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)可以写成(1..10)
    (2.1..5.3)表示(2.1,3.1,4.1,5.1,5.3)
    
  5. 取得数组长度
    @array = (1, 2, 3);
    $scalar = @array;
    
  6. 数组操作的库函数
    sort,reverse,chop,join,split
    排序,反向,去掉最后一个字符,连接,分割