例如文件1.text是这样的一段话:Walmart chief executive Douglas McMillon defends company's decision to invest billions in improving its stores and Internet shopping presence。希望能够找到Mcmillan附近6个英文词中是否出现的decision这个词,应该用哪个函数?非诚勿扰或者[0-9]个英文词都可以,想问问用什么函数
1 回答
蓝山帝景
TA贡献1843条经验 获得超7个赞
while
(
$str
= <DATA>) {
my
@p
= (0xFFFFFFFF, 0xFFFFFFFF);
my
$i
= 0;
while
(
$str
=~ /(\w+)/g) {
if
($1 eq
'decision'
) {
$p
[0] =
$i
;
if
(
abs
(
$p
[0] -
$p
[1]) <= 6){
print
"matched\n"
;
last
;}}
elsif
($1 eq
'McMillon'
) {
$p
[1] =
$i
;
if
(
abs
(
$p
[0] -
$p
[1]) <= 6){
print
"matched\n"
;
last
;}}
$i
++;
}
}
__DATA__
Walmart chief executive Douglas McMillon defends company's decision to invest billions in improving its stores and Internet shopping presence。
添加回答
举报
0/150
提交
取消