From f722131f304f6cb6bb4bb3c9b8ed70eb478c189a Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 16 Apr 2024 15:02:33 +0200 Subject: [PATCH] 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 --- config/cfgroot/general-functions.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) 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]; -- 2.39.5