我有一个字符串,我需要分成三个字符的块.谷歌搜索发现以下代码,工作正常:
$input = "DEADBEEF";
@output = ();
my @output = ( $input =~ m/.{3}/g );
print $_."\n" foreach (@output);
Run Code Online (Sandbox Code Playgroud)
我是Perl初学者; 有人可以向我解释一下表达式的$input =~ m/.{3}/g作用吗?
$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
Run Code Online (Sandbox Code Playgroud)