Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Nested Loops vs Good programming

by graff (Chancellor)
on Nov 14, 2008 at 17:48 UTC ( [id://723693]=note: print w/replies, xml ) Need Help??


in reply to Nested Loops vs Good programming

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://723693]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-04-20 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found