It would be helpful if you provided us with some expected input and output. Running this against strict uncovers two things to consider:
  1. Variable "$ipmapper" will not stay shared at line 19.
    You have used a closure here in passing $ipmapper into your subroutine, and so subsequent calls to fileFindReplace will actually result in a breaking of that link - wanted will hold onto the original copy of $ipmapper while fileFindReplace will create a new one. Consider:
    #!/usr/bin/perl sub print_something { my $x = shift; sub something { return $x; } my $result = something(); print "$x = $result\n"; } print_something(1); print_something(2); __END__ 1 = 1 2 = 1
  2. Global symbol "$oldaddr" requires explicit package name at line 45.
    Global symbol "$newaddr" requires explicit package name at line 46.
    Lexical variables (those declared with my) are scoped to the block level. The variables in question are declared in your foreach loop, and hence they are garbage collected once it has finished. Those variables no longer exist by the time you get to your print and substitution statements. See Variables and Scoping.

My guess on the substitution problem is because . is a metacharacter in regular expressions and you never escaped them. See perlretut for info. Changing your substitution line to $find =~ s/\Q$oldaddr\E/$newaddr/g; would fix this if this is the issue - details in Quote and Quote like Operators.

And my guess on .80south backup files is that you're using that wrong. $^I in perlvar references -i in perlrun, which says:

specifies that files processed by the <> construct are to be edited in-place.
You don't use the <> operator, so it doesn't do that. I would suggest edit-in-place constructs are likely more clever than you want to be for a real script.

In reply to Re: Find Replace code broke and I cannot seem to fix it by kennethk
in thread 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.