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 <michael.tremer@ipfire.org>
This commit is contained in:
Michael Tremer
2024-04-16 15:02:33 +02:00
parent 3cd821c122
commit 98b755225e

View 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];