Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: 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 reply to Re: Nested Loops vs Good programming by graff
in thread Nested Loops vs Good programming by Sporti69

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found