1>更新一个文件
将文件file.txt里的sina替换为google
1.文件file.txt
sina baidu sohu
sina youku sina
tudou qiyi leshi
2.hello.pl
#!/usr/bin/perl -w
use strict;
@ARGV="file.txt";
$^I=".bak";
while (<>) {
s/sina/google/;
print;
}
perl hello.pl
type file.txt
google baidu sohu
google youku sina
tudou qiyi leshi
2>一次更新多个文件
#!/usr/bin/perl -w
use strict;
@ARGV=glob "*.txt";
$^I=".bak";
while (<>) {
s/sina/google/;
print;
}
阅读(919) | 评论(0) | 转发(0) |