紅糖糍粑
2021-10-13 21:11:53
例如文件1.text是這樣的一段話:Walmart chief executive Douglas McMillon defends company's decision to invest billions in improving its stores and Internet shopping presence。希望能夠找到Mcmillan附近6個英文詞中是否出現(xiàn)的decision這個詞,應(yīng)該用哪個函數(shù)?非誠勿擾或者[0-9]個英文詞都可以,想問問用什么函數(shù)
1 回答

藍山帝景
TA貢獻1843條經(jīng)驗 獲得超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
提交
取消