]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
general-function.pl: Add a function to easily set defaults cleanup
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Apr 2024 13:02:33 +0000 (15:02 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Apr 2024 17:44:29 +0000 (19:44 +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 fa90009bb2a54be3a0b15d757c8346f8fac92e6b..a87e5c070ae8ed41ea4a0a89dd94b8ef1cd8b6fe 100644 (file)
@@ -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];