|Pathologically Eclectic Rubbish Lister|
Manipulate deepest values in complex hash structuresby RecursionBane (Acolyte)
|on Apr 29, 2013 at 20:06 UTC||Need Help??|
RecursionBane has asked for the
wisdom of the Perl Monks concerning the following question:
I'm attempting to write a subroutine to perform regexp-based string substitution on the deepest elements of a complex, non-deterministic hash structure (i.e., it could be a HoAoHoA or a HoHoA or a HoA, or any other combination, to any depth). Note that we have no control over this structure. This operation will be performed infrequently enough that I've optimized for readability rather than runtime.
This is the (untested!) code I'm attempting; please let me know if there's an easier way to do this:
I've looked at Hash::Util, but it didn't seem to handle N-deep structures.
Update: One thing I've just thought of is stringifying the entire structure, performing the search and replace, then converting the structure back. Would this be easier/more efficient? Is Data::Dumper the way to go for this?
Any ideas? Thanks in advance!