in reply to Replace an asterisk '*" with the content of array

Like this?

use 5.16.2; my @finalnwlist = ( '192.169.32.0/255.255.255.0', '192.169.72.0/255.255.255.0', '192.169.73.0/255.255.255.0'); my @output = replace_exports(); use Data::Dumper; say Dumper \@output; sub replace_exports { chomp(my @lines = <DATA>); my @changes; foreach my $line (@lines) { foreach my $server (@finalnwlist) { my $output = $line; $output =~ s/\*/$server/g or next; push(@changes,$output); } } return @changes; } __DATA__ /file1 *(rw,sync,no_root_squash,no_subtree_check) /file2 *(ro,sync,no_root_squash,no_subtree_check) # shares for Tsp InstallServer file3 *(ro,sync,no_subtree_check)

Replies are listed 'Best First'.
Re^2: Replace an asterisk '*" with the content of array
by GotToBTru (Prior) on Sep 18, 2015 at 13:59 UTC

    You're losing the comment line.

    use 5.16.2; my @finalnwlist = ( '192.169.32.0/255.255.255.0', '192.169.72.0/255.255.255.0', '192.169.73.0/255.255.255.0'); my @output = replace_exports(); use Data::Dumper; say Dumper \@output; sub replace_exports { chomp(my @lines = <DATA>); my @changes; foreach my $line (@lines) { if ($line !~ /\*/) { push(@changes,$line) } else { foreach my $server (@finalnwlist) { my $output = $line; $output =~ s/\*/$server/g; push(@changes,$output); } } } return @changes; } __DATA__ /file1 *(rw,sync,no_root_squash,no_subtree_check) /file2 *(ro,sync,no_root_squash,no_subtree_check) # shares for Tsp InstallServer file3 *(ro,sync,no_subtree_check)
    Dum Spiro Spero

      Yeah, I know :) I don't want to do everything for OP