MikeDexter has asked for the wisdom of the Perl Monks concerning the following question:
Hi I am having a couple small issues with a section of code. The issues are
(1.) The .80south backup files are not being created
(2.) The $oldaddr and $newaddr print lines near bottom of the script are empty, The value is not there.
(3.) At one point I had the value there but it was not finding and replacing the entries.
(4.) At one point is was finding and replacing the entries but it wrote back to the file with funny newlines, so the content was all scrambled.
I would appreciate any help you can provide because I just keep fixing one thing only to create a new error
Here is my code section
sub fileFindReplace { my $searchpath = shift; my $ipmapper = shift; #print "searchpath : <$searchpath>\n"; #print "ipmapper : <$ipmapper>\n\n"; find(\&wanted, $searchpath); sub wanted { local (@ARGV) = shift; local ($^I) = ".80south"; open (INPUTFILE, $ipmapper) or die "Could not open file: $!"; my (@mapper) = <INPUTFILE>; foreach my $line (@mapper) { my ($oldaddr, $newaddr,) = split (/\t/, $line, 2); } close INPUTFILE; my $filename = $File::Find::name; return unless -f $filename; return unless $filename =~ /$ARGV/; open (FR, $filename) or print "Could not read $filename\n" && +return; my (@file) = <FR>; close FR; print "read ", scalar(@file), " lines from $filename\n"; open (FW, ">$filename") or print "Could not open for write $fi +lename\n" && return; unless ( open FW, ">$filename" ) { print "could not open $filename for write: $!"; return; } foreach my $find (@file) { print "<MIKE1 Filename is [$filename] \n"; print "<MIKE Searching [$filename] for updates\n"; print "<MIKE Changing OLD IP ADDRESS: $oldaddr\n"; print "<MIKE To NEW IP ADDRESS: $newaddr\n"; $find =~ s/$oldaddr/$newaddr/g; print FW $find; } close FW; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Find Replace code broke and I cannot seem to fix it
by kennethk (Abbot) on Mar 30, 2010 at 20:57 UTC | |
|
Re: Find Replace code broke and I cannot seem to fix it
by GrandFather (Saint) on Mar 30, 2010 at 21:08 UTC | |
|
Re: Find Replace code broke and I cannot seem to fix it
by toolic (Bishop) on Mar 30, 2010 at 21:07 UTC |