- 论坛徽章:
- 3
|
- use File::Find;
- @ARGV=('.') unless @ARGV;
- $dir=shift @ARGV;
- find(\&edits, $dir);
- sub edits() {
- $seen=0;
- if( -f and /.htm?/ )
- { $file=$_;
- open FILE, $file;
- @lines=<FILE>;;
- close FILE;
- for $line (@lines){
- if($line=~s/www.163.com/www.888.com/){$seen++;}
- }
- open FILE, ">;$file";
- print FILE @lines;
- close FILE;
- print "\nFound in $File::Find::name\n" if $seen >; 0;
- }
- }
复制代码
我在网上搜集了以下,基本上就能满足替换要求!
Because of this words:
"This script can be used as a starting point for more useful or powerful scripts. Readers are encouraged to look up this kind of editing in the Perl cookbook."
我决定用下面的但是看不懂,麻烦大家看看,帮忙解释以下(详细一点啊
- use File::Find;
- @ARGV = ('.') unless @ARGV;
- $dir = shift @ARGV;
- find(\&edits, $dir);
- sub edits() {
- return unless -f; #skip directories
- $seen = 0;
- $file = $_;
- #Uncomment next line if you want multi-line edits
- #undef $/;
- local $^I=".backup";
- #Warning - heavy magic here
- local @ARGV = ($file);
- while(<>;) {
- #Remember to use the s option if doing multiline edits
- $seen++ if s/Lesson/Chapter/;
- print;
- }
- print "Found in $File::Find::name\n" if $seen >; 0;
- #Comment out if you want to keep the backup
- #unlink $file.".backup";
- }
复制代码
谢谢 |
|