From: Michael Tremer Date: Tue, 16 Apr 2024 13:02:33 +0000 (+0200) Subject: general-function.pl: Add a function to easily set defaults X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f722131f304f6cb6bb4bb3c9b8ed70eb478c189a;p=people%2Fms%2Fipfire-2.x.git general-function.pl: Add a function to easily set defaults This function can be used to set values in a hash if they have not been set, yet. Signed-off-by: Michael Tremer --- diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index 98c8b9e36..86e9413d1 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -278,6 +278,17 @@ sub get_aliases } } +sub set_defaults($$) { + my $hash = shift; + my $defaults = shift; + + foreach my $key (keys %$defaults) { + unless (defined($hash->{$key})) { + $hash->{$key} = $defaults->{$key}; + } + } +} + sub readhash { my $filename = $_[0];