From 8fcc9b0e2fddf3a0d9d15330893cb5af19da1538 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 29 Jun 2020 00:52:08 -0400 Subject: [PATCH] `group_hosts_by` improvements * Don't modify `$config{$h}{$v}` if variable `$v` for host `$h` is `undef`. * Tolerate the user passing `wantip` or duplicate keys. --- ddclient | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ddclient b/ddclient index 112acb8..fa2222c 100755 --- a/ddclient +++ b/ddclient @@ -2355,13 +2355,11 @@ sub extract_ipv6 { ###################################################################### sub group_hosts_by { my ($hosts, $attributes) = @_; - + my %attrs = (map({ ($_ => 1) } @$attributes), 'wantip' => 1); + my @attrs = sort(keys(%attrs)); my %groups = (); foreach my $h (@$hosts) { - my @keys = (@$attributes, 'wantip'); - map { $config{$h}{$_} = '' unless exists $config{$h}{$_} } @keys; - my $sig = join(',', map { "$_=$config{$h}{$_}" } @keys); - + my $sig = join(',', map({ sprintf("%s=%s", $_, $config{$h}{$_} // '') } @attrs)); push @{$groups{$sig}}, $h; } return %groups;