]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
general-function.pl: Add a function to easily set defaults
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Apr 2024 13:02:33 +0000 (15:02 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Apr 2024 13:02:33 +0000 (15:02 +0200)
This function can be used to set values in a hash if they have not been
set, yet.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/cfgroot/general-functions.pl

index 98c8b9e3699ce1b91968d83ce9068f6da4a8663b..86e9413d17f0ae7f102c110c492597b43d532f58 100644 (file)
@@ -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];