关于perl从文件中查找特定字符串:,具体请看下面!

例如文件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]个英文词都可以,想问问用什么函数

红糖糍粑
浏览 429回答 1
1回答

蓝山帝景

while&nbsp;($str&nbsp;=&nbsp;<DATA>)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;my&nbsp;@p&nbsp;=&nbsp;(0xFFFFFFFF,&nbsp;0xFFFFFFFF);&nbsp;&nbsp;&nbsp;&nbsp;my&nbsp;$i&nbsp;=&nbsp;0;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;($str&nbsp;=~&nbsp;/(\w+)/g)&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;($1&nbsp;eq&nbsp;'decision')&nbsp;&nbsp;&nbsp;&nbsp;{$p[0]&nbsp;=&nbsp;$i;&nbsp;if&nbsp;(abs($p[0]&nbsp;-&nbsp;$p[1])&nbsp;<=&nbsp;6){print&nbsp;"matched\n";&nbsp;last;}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif&nbsp;($1&nbsp;eq&nbsp;'McMillon')&nbsp;{$p[1]&nbsp;=&nbsp;$i;&nbsp;if&nbsp;(abs($p[0]&nbsp;-&nbsp;$p[1])&nbsp;<=&nbsp;6){print&nbsp;"matched\n";&nbsp;last;}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$i++;&nbsp;&nbsp;&nbsp;&nbsp;}}__DATA__Walmart&nbsp;chief&nbsp;executive&nbsp;Douglas&nbsp;McMillon&nbsp;defends&nbsp;company's&nbsp;decision&nbsp;to&nbsp;invest&nbsp;billions&nbsp;in&nbsp;improving&nbsp;its&nbsp;stores&nbsp;and&nbsp;Internet&nbsp;shopping&nbsp;presence。
打开App,查看更多内容
随时随地看视频慕课网APP