You need to identify the lines without * to let those pass through. Then loop over the network list but use a copy of the line in the substitution each time
poj#!perl use strict; my @finalnwlist = qw( 192.169.32.0/255.255.255.0 192.169.72.0/255.255.255.0 192.169.73.0/255.255.255.0); replace_exports('exports.txt'); sub replace_exports { my $filename = shift; open IN,'<',$filename or die "Error opening $filename for read : $!"; my @lines = <IN>; close IN; open OUT, '>', 'chg_'.$filename or die "Error opening $filename for write : $!"; for (@lines) { chomp; if (m/\*/){ print "Change $_\n"; for my $nw (@finalnwlist){ my $copy = $_; $copy =~ s/\*/$nw/; print OUT $copy."\n"; } } else { print OUT $_."\n"; } } close OUT }
In reply to Re^3: Replace an asterisk '*" with the content of array
by poj
in thread Replace an asterisk '*" with the content of array
by deep27ak
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |