• perl备忘


    List Operators:

      sort reverse grep map 

      my @castways = sort qw( first second third); # qw 给单词自动加上双引号

      grep: 从list中一个一个的取出,然后添加到$_中,然后通过测试标量的值,为true的话添加到输出列表中

      some example:

              my @lunch_choices = grep &is_edible($_), @gilligans_posessions

              my @results = grep EXPR,@input_list;

           my @bigger_than_10 = grep $_ > 10 , @input_numbers;

          map: 也是通过一些规则改变列表,感觉map可以增加列表的元素,而grep更注重过滤

         my @input_numbers = (1 2 3 4 5 6 );

            my @result = map $_ + 100 , @input_numbers;

         my @result = map { $_ , 3* $_} @input_numbers;

    Reference:

      my @array = ( 1 2 3 4 );

      my $ref = @array;

      $ref->[0]  调用方式  ,多级箭头可以简化 $ref->[0]->[1]->[2]  == $ref->[0][1][2]

      @$ref 又可以变回数组形式

    正则表达式的高级形式:

       末尾加x,可以给正则表达式换行,提高可读性

      ?#可以给正则表达式做注释

    表达式

    方向

    说明

    (?=xxx)

    正向预搜索(向右)

    正向预搜索,判断当前位置右侧是否能匹配指定表达式

    (?!xxx)

    正向预搜索否定,判断当前位置右侧是否不能够匹配指定表达式

    (?<=xxx)

    反向预搜索(向左)

    反向预搜索,判断当前位置左侧是否能够匹配指定表达式

    (?<!xxx)

    反向预搜索否定,判断当前位置左侧是否不能够匹配指定表达式

    同时不匹配括号中的内容。

      

  • 相关阅读:
    135. Candy(Array; Greedy)
    69. Sqrt(x) (Divide-and-Conquer)
    109. Convert Sorted List to Binary Search Tree (List; Divide-and-Conquer, dfs)
    108.Convert Sorted Array to Binary Search Tree(Array; Divide-and-Conquer, dfs)
    34. Search for a Range (Array; Divide-and-Conquer)
    35. Search Insert Position (Array; Divide-and-Conquer)
    82. Remove Duplicates from Sorted List II (List)
    python dict list tuple
    python unix时间戳
    字符串哈希函数
  • 原文地址:https://www.cnblogs.com/zhanglanyun/p/3305995.html
Copyright © 2020-2023  润新知