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
Global symbol "$oldaddr" requires explicit package name at line 45.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.
Global symbol "$newaddr" requires explicit package name at line 46.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |