我只是想搜索一个字符串“ Kumar”,然后用Mahi替换该字符串。但是产量没有到来。任何人都可以指出我在哪里做错了。
#!/usr/bin/perl -w
use strict;
open(my $fh, "+>","test.txt") || die "File not found";
my @lines = <$fh>;
my @newlines;
my $count;
foreach my $line(@lines) {
if($line =~/Kumar/i){
$line =~ s/Kumar/Mahi/ig;
print $fh $line;
#push(@newlines,$line);
$count++;
}
}
#print $fh @newlines;
close($fh);
txt文件:
Kumar Yadav vivek Kumar Yadav
qualcomm Kumar Yadav tarun Kumar sumit
adbd Kumar shahi Kumar sinha
open($fh, "<", "file.txt") or die "cannot open file:$!\n";
while( my $line = <$fh>){
$line =~ s/Kumar/Mahi/;
print $line ."\n";
}
close($fh);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句