Posted By

noah on 07/03/07


Tagged

table object default pattern compare hash 2001 lookup


Versions (?)

provide default values for a hash


 / Published in: Perl
 

  1. ################
  2. #COMPARE_N_SUBSTITUTE
  3. #Compare a hash to a fall-through hash. If any values are present in the fall-through and not in the current values then insert them in the DYC hash.
  4. #compare_n_substitute(hash1, hash2) #insert key-value-pairs from hash2 into hash1 only if those pairs are not defined in hash1.
  5. #compare_n_substitute(\%hash, \%default)
  6. sub compare_n_substitute(\%\%) {
  7. my ($hashref, $fallthrough_hashref) = @_;
  8. for my $key (keys %$fallthrough_hashref) {
  9. unless (defined($$hashref{$key})) {
  10. $$hashref{$key} = $$fallthrough_hashref{$key};
  11. }
  12. }
  13. }

Report this snippet  

You need to login to post a comment.