Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Replace an asterisk '*" with the content of array

by SimonPratt (Friar)
on Sep 18, 2015 at 12:13 UTC ( [id://1142405]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1142405]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-23 18:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found