split/PATTERN/, EXPR 而使用单引号(或者双引号)来分隔空格(whitespace)是一种特殊的例子: Asa specialcase,ifthe expression is a single space (" "), thefunctionsplits on whitespace justassplitwithnoargumentsdoes.Thus,split(" ") can be used to emulate awk ’sdefaultbehavior.Incontrast,split(/ /...
"If PATTERN is also omitted, splits on whitespace (after skipping any leading whitespace)." That means you should just be able to say: Code: @DATA = split(//,$string); Tracy Dryden tracy@bydisn.com Meddle not in the affairs of dragons, For you are crunchy, and good with...
Alternatively, I can use-a, which automatically splits on whitespace and puts the result in@F. I work on the third element then output@Fagain: $ perl -lane'$F[2]=reverse $F[2]=~tr/ATGC/TACG/r; print "@F"'test.txt ABC DEF CTAATC GHK ABC DEF GACGCC GHK ABC DEF GGAATT GHK ...
GNU General Public License, which may be foundinthe Perl5source kit. Complete documentationforPerl, including FAQ lists, should be foundonthissystemusing"man perl"or"perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page.12345678 ...
split [ PATTERN [ , EXPR [ , LIMIT ] ] ] 12 此函数将字符串拆分为字符串数组,并将其返回。 如果指定了LIMIT,则最多分割为该字段数。 如果省略PATTERN,则拆分空格。 以下是示例 - #!/usr/bin/perl # define Strings $var_string = "Rain-Drops-On-Roses-And-Whiskers-On-Kittens"; $var_names =...
split用拆分模式扫描指定的字符串并返回字段列表。只要模式在某处匹配成功,该出就是当前字段的借位,下一字段的开头。任何匹配模式的内容都不会出现在返回字段中。 split会保留开头出的空字段,却舍弃结尾处的空字段。 my @fileds=split /:/,":::a:b:c:::"; #得到(“”,“”,“”,“a”,“b”,"c")...
The -a switch (see perlrun splits on whitespace and puts the list in @F: % cat ~/.bash_history | perl -lane 'if ($F[0] eq "sudo"){$hash{$F[1]}++ } else { $hash{$F[0]}++ }; $count ++; END { @top = map { [ $_, $hash{$_} ] } sort { $hash{$b} <=> ...
Split on whitespace except when inside parens Prime numbers \K, (*SKIP), (*FAIL) revisited Branch reset Matching valid month/day strings - non-capturing vs branch reset groups Capture items from a list Nested parens Other resources * Regex 101 * Regex tester * ReGeX cRoSsWoRdS! * regex golf...
split 操作 另一个使用正则表达式的操作是 split , 它根据某个模式将字符串分割开。这对于由制表符分割开,冒号分割开,空白分割开,或者任意字符分割开的数据是非常有用的。任何可在正则表达式之中 (通常,是一个简单的正则表达式) 指定分离符 (separator) 的地方,均可用 split。其形式如下: @fields = split /sep...
return s; } 注意这里的正则不能直接写/\s+/g因为会匹配到空格。