From f13d6e7d9e9fc11a04dabab5cb86486aaec500c6 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Mon, 2 Dec 2002 23:36:58 +0000 Subject: (add2hosts): use output and pixelization --- perl-install/network/network.pm | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'perl-install') diff --git a/perl-install/network/network.pm b/perl-install/network/network.pm index 14a4fdaf3..2f20d131a 100644 --- a/perl-install/network/network.pm +++ b/perl-install/network/network.pm @@ -143,28 +143,15 @@ sub write_interface_conf { sub add2hosts { my ($file, $hostname, @ips) = @_; - my %l; - $l{$_} = $hostname foreach @ips; - foreach (cat_($file)) { - m/\s*(\S+)(.*)/; - my ($ip, $host) = ($1, $2); - $l{$ip} ||= $host if $host !~ /^\s*$hostname\s*$/; - } + my %l = map { if_(/\s*(\S+)(.*)/, $1 => $2) } + grep { !/\s+\Q$hostname\E\s*$/ } cat_($file); + + my $sub_hostname = $hostname =~ /(.*?)\./ ? " $1" : ''; + $l{$_} = "\t\t$hostname$sub_hostname" foreach grep { $_ } @ips; + log::l("writing host information to $file"); - local *F; - open F, ">$file" or die "cannot write $file: $!"; - while (my ($ip, $v) = each %l) { - $ip or next; - print F $ip; - if ($v =~ /^\s/) { - print F $v; - } else { - print F "\t\t$v"; - print F " $1" if $v =~ /(.*?)\./; - } - print F "\n"; - } + output($file, map { "$_$l{$_}\n" } keys %l); } # The interface/gateway needs to be configured before this will work! -- cgit v1.2.1