我需要在perl=
和)
使用 perl 之间复制句子的内容。比如说:
$temp="06/18/2012 08:35:35(PID=2150)";
现在我需要将值复制到变量2150
之间。=
)
$temp2
我需要在perl=
和)
使用 perl 之间复制句子的内容。比如说:
$temp="06/18/2012 08:35:35(PID=2150)";
现在我需要将值复制到变量2150
之间。=
)
$temp2
使用正则表达式很容易实现:
my ($temp2) = $temp =~ /=(\d+)\)/;
只需查找 和 之间的数字=
序列\)
。由于括号用于捕获组,因此必须对右括号进行转义。
必须$temp2
用括号括起来的原因是因为您需要强制列表上下文返回匹配结果。在标量上下文中,您只会得到匹配的数量;1 在这种情况下。
仅使用 index() 和 substr() (作为练习,如果有的话;)。
$temp="06/18/2012 08:35:35(PID=2150)";
$temp = substr $temp, index($temp, "=") + 1, (index($temp, ")") - 1) - index($temp, "=");
print $temp;