作为一名非Perl程序员,我想确定我已经很好地理解了一个我将要移植到Python的构造,
使用时:
if (s/^([$PChar])(.)/$2/) {
print $1,"\n";
$finished = 0;
}
我真的不确定匹配/替换是否在打印$ 1之前完成?并且它是在当前缓冲区内进行“inplace”(这是$ F,即逐行readed的$ _,在其空格字符上拆分),即改变它(所以如果我理解的话,([$ PChar])当@字符串的开头在上述陈述中完全条纹化/丢失时?)
编辑:不可能它没有丢失,第一个括号部分被捕获,然后打印为$ 1 +新行字符然后......不,不明白什么变成$ 2 ...可能缓冲区更改为第二个括号部分? /编辑结束。是否有任何环境或允许在Win平台上进行逐步调试的最佳环境是什么?我知道有这个,我不会问这个问题。而且我不需要学习Perl,只是为了能够阅读和修改这个脚本。
这是一个充满活力的部分:
@F = split;
for( $j=0; $j<=$#F; $j++) {
my $suffix="";
$_ = $F[$j];
# separate punctuation and parentheses from words
do {
$finished = 1;
# cut off preceding punctuation
if (s/^([$PChar])(.)/$2/) {
print $1,"\n";
$finished = 0;
}
# cut off trailing punctuation
if (s/(.)([$FChar])$/$1/) {
$suffix = "$2\n$suffix";
$finished = 0;
}
整个脚本tokenize.pl可以看到here而原始tar.bz可以从here
看到最好的问候
答案 0 :(得分:2)
# try to delete the first character from the string contained in
# $_ if that character is one of the characters contained in
# the string $PChar. The deletion is done by replace the first and
# second character by only the second character.
if (s/^([$PChar])(.)/$2/) {
# if the replacement was successful, print the deleted character.
print $1,"\n";
$finished = 0;
}