Na potrzeby dostosowana adresów URL do innej konfiguracji innego serwera wykorzystałem następujący skrypt:
#!/usr/bin/perl -w use strict; undef $/; ## na potrzeby czytania każdego pliku (process_file) sub recurse($) { my($path) = @_; ## append a trailing / if it's not there $path .= '/' if($path !~ /\/$/); ## print the directory being searched print STDERR $path,"\n"; ## loop through the files contained in the directory for my $eachFile (glob($path.'*')) { ## if the file is a directory if( -d $eachFile) { ## pass the directory to the routine ( recursion ) recurse($eachFile); } else { ## przetwarzaj plik process_file ($eachFile); } } } sub process_file { my $file = shift; ## Tylko pliki .html i .php if ($file =~ /\.html|\.php$/) { my $tmp_file = "$file.temp"; rename($file, $tmp_file); open (F, $tmp_file); open (FO, ">$file"); my $ff = <F>; ## zamień bezwględne URLe na lepsze $ff =~ s/href=(["'])http:\/\/gnu.univ.gda.pl\/~tomasz/href=$1/g; ## zamień $ff =~ s/src=(["'])http:\/\/gnu.univ.gda.pl\/~tomasz/src=$1/g; ## zamień print STDERR "-> $file\n"; print FO $ff; close(F); close (FO); } } ## initial call ... $ARGV[0] is the first command line argument recurse($ARGV[0]);
Wymieniając procedurę process_file
można oczywiście ww. skrypt zaadaptować do innych zadań, np. poprawienia
zepsutej daty modyfikacji plików:-)