in reply to Return to original loop
BTW, don't use for with <>, use while. Also, use \Q$ip\E to treat the dots literally.
chomp(my @data = <DATA>); while (my $confLine = <$in>) { if ($confLine =~ /ip4-address address="/) { # No need to backslash + ". for my $ip (@data) { if ($confLine =~ /ip4-address address="\Q$ip/) { $confLine =~ s{/>}{update"/>}; } } } print {$out} $confLine; }
Or
my $data_start = tell DATA; while (my $confLine = <$in>) { if ($confLine =~ /ip4-address address="/) { # No need to backslash + ". seek DATA, $data_start, 0; while (my $ip = <DATA>) { chomp $ip; if ($confLine =~ /ip4-address address="\Q$ip/) { $confLine =~ s{/>}{update"/>}; } } } print {$out} $confLine; }
Update: quotemeta added.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Return to original loop
by stroke (Acolyte) on Oct 15, 2015 at 14:19 UTC | |
by Athanasius (Archbishop) on Oct 15, 2015 at 15:59 UTC | |
by stroke (Acolyte) on Oct 15, 2015 at 16:07 UTC |