Keep It Simple, Stupid | |
PerlMonks |
Re: Nested Loops vs Good programmingby graff (Chancellor) |
on Nov 14, 2008 at 17:48 UTC ( [id://723693]=note: print w/replies, xml ) | Need Help?? |
You said:
I have quite some nested loops that all need values from upper loops. But in your code snippet, it seems like the only need you have for the values from upper loops is to use the hash keys and array index counters for navigating through the "doc" structure returned by XML::Simple. If that is also the situation for your "actual" application, then the suggestion about about using recursion will make that a moot point: your recursive sub simply takes as a parameter the hash ref -- on the initial (outermost) call, this is the hash ref returned by XML::Simple::XMLin. On subsequent (recursing) calls, it's a hash ref at successively lower levels of the structure. OTOH, if there are tag attributes at level 1, and you want to associate those with information that gets parsed at level 4 or whatever, you'll probably want your recursive sub to take additional parameters, so that info gleaned from an upper level can be passed to lower levels.
In Section
Seekers of Perl Wisdom
|
|