Welcome to the Monastery | |
PerlMonks |
Augmenting and reducing data structuresby sciurius (Sexton) |
on Apr 22, 2021 at 12:22 UTC ( [id://11131585]=perlquestion: print w/replies, xml ) | Need Help?? |
sciurius has asked for the wisdom of the Perl Monks concerning the following question: Assume you have a (big) perl data structure, a hash, of which all keys have values that can be scalars, arrays or hashes. Arrays and hashes can contain scalars, arrays or hashes, and so on. For example: $orig = { a => { b => [ 'c', 'd' ], e => [ [ 'f' ] ] } }; Assume there is an operation 'augment' that takes this data structure and another (smaller) structure. The original data structure will be modified so that all the data from the smaller structure is now in the original structure as well. For example, augmenting the strucure above with { a => { e => [ [ 'g' ] ] } } will yield { a => { b => [ 'c', 'd' ], e => [ [ 'g' ] ] } } What I'm looking for is the reversed operation, let's call it 'reduce', that takes the original and augmented structures as arguments, and returns the (minimal) structure that is needed to augment the original. I'm sure that there are modules that already implement this but I haven't been able to identify them... A cut/paste ready test program:
Back to
Seekers of Perl Wisdom
|
|