use Cwd; use XML::Simple; use Data::Dumper; my $dir = "files/html"; my $xmlfile = ""; # need a full filepath because a relative filepath affected by the File::Find changing the current directory my $file; my $t =0; #### search all files in the directory and perform a search and replace using an xml file #### as the sourse of the matched string and the replacement string. use File::Find; find(\&searchlines, $dir); ################### functions ####################### #### searchlines uses a filehandle to open up all the files and search them line by line sub searchlines { #print "$File::Find::name \n"; return unless -f $_; open(FILE,$_) || die "Cannot open $_ \n"; my @data = ; foreach my $line (@data){ ## pass the curent line of text to the next function ## xmlfeed($line); } close(FILE); } #### xmlfeed uses the xml file to get a list of the strings to replace sub xmlfeed { my $linedata = shift @_; #print $linedata; # create object $xml = new XML::Simple(); # read XML file $data = $xml->XMLin($xmlfile); # processes the xml file one sheet at a time # # # # # # # foreach $e (@{$data->{Sheet1}}) { #print $e->{Sheet1}, "\n"; # print "LinkToPage: ", $e->{LinkToPage}, " \nNew page", $e->{New_location}, "\n"; &match($linedata , $e->{LinkToPage}, $e->{New_location} ) #print "\n"; } } #### matches the current line against the string in # performs a substitution on the stout. sub match { my $in = shift @_; my $originalURL = shift @_; my $newURL = shift @_; #$in =~ s/$originalURL/$newURL/; #$in =~ s/$originalURL/$newURL/ #print "$originalURL, $newURL\n" ; if($in =~ m/$originalURL/) { $t++; print "Matched x " . "$t \n" ; print "$File::Find::name \n"; } }