用perl写一个程序,对文本文件进行修改,如果匹配到第一个条件的时候就不做任何修改,直接退出;否则继续

用perl写一个程序,对文本文件进行修改,如果匹配到第一个条件的时候就不做任何修改,直接退出;否则继续,第1张

my $output

my $not_modify_flag

While(my $readin=<FH>){

if ($readin 匹配第一个条件){$not_modify_flag=1last} ## 匹配第一个条件,标记一下后,直接跳出循环

elsif ($readin 匹配第二个条件){ $output.= $修改后的内容}

elsif ($readin 匹配第三个条件){ $output.= $修改后的内容}

else {$output.=$readin} ## 如果不匹配上述三个条件,则原样输出

}

close FH

if (not defined $not_modify_flag){

print $output## 最后输出

}

else {

print "匹配第一个条件,不做修改"."\n"

}

exit(0)

我试过了,我这里是正常的,可以一直下去(不过也就试到了4000多而已)

只是有个特点,大约每300多次以后,会出现类似暂停的效果(应该是connection时间变长吧)

然后又可以连续300多条,估计是路由器自己的保护机制

所以,程序应该是没有问题的,下面是结果

2177 failed

2178 failed

2179 failed

2180 failed

2181 failed

2182 failed

2183 failed

2184 failed

2185 failed

2186 failed

2187 failed

2188 failed

2189 failed

2190 failed

2191 failed

2192 failed

2193 failed

2194 failed

2195 failed

2196 failed

2197 failed

2198 failed

2199 failed

2200 failed

2201 failed

2202 failed

2203 failed

2204 failed

2205 failed

2206 failed

2207 failed

2208 failed

2209 failed

2210 failed

2211 failed

2212 failed

2213 failed

2214 failed

2215 failed

2216 failed

2217 failed

2218 failed

2219 failed

2220 failed

2221 failed

2222 failed

2223 failed

2224 failed

2225 failed

2226 failed

2227 failed

2228 failed

2229 failed

2230 failed

2231 failed

2232 failed

2233 failed

2234 failed

2235 failed

2236 failed

2237 failed

2238 failed

2239 failed

2240 failed

2241 failed

2242 failed

2243 failed

2244 failed

2245 failed

2246 failed

2247 failed

2248 failed

2249 failed

2250 failed

2251 failed

2252 failed

2253 failed

2254 failed

2255 failed

2256 failed

2257 failed

2258 failed

2259 failed

2260Terminating on signal SIGINT(2)

输出完成 (耗时 11 秒) - 已被用户取消。

system 'pause'

应该可以,等待一个标准输入应该也可以,我都用过,输入空格不会退出

对了,这个标准输入最终要输入一个回车才可以,你要是任意输入的话,就pause好了,


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7951102.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-11
下一篇 2023-04-11

发表评论

登录后才能评论

评论列表(0条)

保存