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=refs%2Fheads%2Fcleanup;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 fa90009bb..a87e5c070 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -202,6 +202,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];