We don't bite newbies here... much | |
PerlMonks |
How to walk through convoluted data?by perl-diddler (Chaplain) |
on Jul 19, 2021 at 19:20 UTC ( [id://11135180]=perlquestion: print w/replies, xml ) | Need Help?? |
perl-diddler has asked for the wisdom of the Perl Monks concerning the following question:
Posting a question here, because even if I get the code to work, it looks ugly/feels icky.
The code is walking a data structure, which has some indirections in it due to multiple versions of the source data...I'll try to explain. I'm D/L rpm files associated with a 'Repo'. The Repo (a rolling release called tumbleweed) is released as often as daily. Each release has a primary.xml file that contains all the files in the release. Some of those rpms may be new, others may be the same as in previous releases. As you download releases, you only need to d/l the new rpms. I am trying to keep the past 4 d/l's which may not be from consecutive releases. As I d/l new file lists (from primary.xml), I eventually end up with unreferenced rpm's on disk. I want a way to be able to expire the old releases, either as I download new ones (idea) or by running an expiration script after I download a new version. My data structures have changed more than a few times as I have been evolving a program that downloads 1 release to one that downloads multiple releases, but that will expire old files. The part I'm questioning right now is when I got to: and realized I was hitting some repetition. So I extracted some similar code to continue: Realized I need to handle the storing of the optional param and not liking all that growing repetition in each line, my latest code looks more like: Since I'm going deeper and deeper in the data structure I figure I might as well store some of that walk into '$obj' so I can re-use it and not spell it out each time. But this feels like a kludge/hack. Maybe that's what it will take/be, but I thought I put it here to see if anyone had done similar and how they did it (preferably without throwing out the baby w/they bath-water, i.e. w/o a complete rewrite of 1600-1700 lines of code. Sigh. FWIW -- the "cpeid" is my daily version (20210719), so I'm trying to create a single "name" database (RepoDB) for all the versions, and off of that a "version-release" for each rpm-VR that would exist for each from each name, and have the VR point to the rest of the info for a given rpm (including what cpeid(s) it was in). Theoretically, on the last time through the loop, if I find a "VR" that isn't tagged, it can be removed. At 1700+ lines, there's quite a bit of code not shown. Sadly, since this script has morphed from a simple D/L script, to whatever I will have due to needs to "expire" disconnected RPM versions, There's been a great deal of code-refactoring on the fly. mkBless is a routine that "ensures" there is a Blessed obj, like my mkARRAY/mkHASH ensure there is an ARRAY or HASH where it is pointing to and if not, then do something about it. They are not usually needed due to autovivification, but there are a few places where auto-vivification doesn't work (that need helper routines). I'm not specifically trying to solve some problem (that I know of, yet), but wondering if others have had to follow a bunch of nested data and how that worked out (or if you have any, *cough*, pointers....?)
Back to
Seekers of Perl Wisdom
|
|