List Operators:正则表达式
sort reverse grep map 数组
my @castways = sort qw( first second third); # qw 给单词自动加上双引号session
grep: 从list中一个一个的取出,而后添加到$_中,而后经过测试标量的值,为true的话添加到输出列表中测试
some example:spa
my @lunch_choices = grep &is_edible($_), @gilligans_posessionsci
my @results = grep EXPR,@input_list;input
my @bigger_than_10 = grep $_ > 10 , @input_numbers;io
map: 也是经过一些规则改变列表,感受map能够增长列表的元素,而grep更注重过滤table
my @input_numbers = (1 2 3 4 5 6 );ast
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) |
反向预搜索否认,判断当前位置左侧是否不可以匹配指定表达式 |
同时不匹配括号中的内容。