diff --git a/opentrafficshaper/utils.pm b/opentrafficshaper/utils.pm index 88589fd758664827ee6786630a5364b26649e723..0a0b338a2a75ba0235d3240c5791389f446aca2d 100644 --- a/opentrafficshaper/utils.pm +++ b/opentrafficshaper/utils.pm @@ -27,6 +27,7 @@ our (@ISA,@EXPORT,@EXPORT_OK); @ISA = qw(Exporter); @EXPORT = qw( prettyUndef + getHashChanges toHex isVariable isUsername @@ -53,6 +54,27 @@ sub prettyUndef } +# Function to return the changes between two hashes using a list of keys +sub getHashChanges +{ + my ($orig,$new,$keys) = @_; + + + my $changed = { }; + + foreach my $key (@{$keys}) { + # We can only do this if we have a new value + if (defined($new->{$key})) { + if (!defined($orig->{$key}) || $orig->{$key} ne $new->{$key}) { + $changed->{$key} = $new->{$key}; + } + } + } + + return $changed; +} + + # Return hex representation of a decimal sub toHex {