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; } }

In reply to Find Replace code broke and I cannot seem to fix it by MikeDexter

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.