1

我有一个字符串,我需要将其拆分为三个字符的块。谷歌搜索发现以下代码,它工作正常:

$input = "DEADBEEF";
@output = ();
my @output = ( $input =~ m/.{3}/g );
print $_."\n" foreach (@output);

我是 Perl 初学者;有人可以向我解释一下这个表达式的$input =~ m/.{3}/g作用吗?

4

1 回答 1

6
$input - scalar variable
=~     - apply regular expression
m      - Match (in list context so return a list of matched substrings)
/      - start of expression
.      - any character
{3}    - 3 times
/      - end of expression
g      - globally
于 2012-09-12T18:16:33.263 回答