Jim wrote:
I propose the following code will properly take the variable $read_line
and substitute $new_ip_address for all occurrences of $old_ip_address.
Basically the snippet of code is from some software that will update a
set of old ip addresses with new ip addresses within a file. Can anyone
find any fault in it or see if I overlooked something, please? Of
particular concern is if I've considered enough by wrapping my
substitution string within (\D*)

$old_ip_address = "1.2.3.4";
$new_ip_address = "5.6.7.8"
$old_ip_address_regexp = $old_ip_address;
$old_ip_address_regexp =~ s/\./\\./ig;
$read_line =~ s/(\D*)$old_ip_address_regexp(\D*)/$1$new_ip_address$2/ig;

(\D*) won't work because it can match zero characters.  Just use (\D)



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to