my $data="#1#2#3#4#"; while ( $data =~ /#(\d)#/g ) { print $1,"\n"; }
但是如果我能够将下一个位置的开始倒数1,我会得到偶数和奇数.
这不起作用:pos()= pos() – 1;
我知道我可以用拆分完成这个.但这并没有回答我的问题.
for (split /#/,$data) { print $_,"\n"; }
从perldoc起
perldoc
Returns the offset of where the last m//g search left off for the variable in question ($_ is used when the variable is not specified)
所以,
pos($data) = pos($data) - 1;