Also completely un-related to your problem... you can eliminate your print_file_name sub, and use the basename function from the File::Basename module instead. Less code for you to maintain, and it's more portable.

Regarding your problem... if it is possible for you to post a very small sample of your XML code here, please do so, as that would allow any of us to easily duplicate your problem. I followed your link, but it asked me to create some kind of account. That's too much of a commitment for me :)

Also, your code layout is a little difficult to follow. I used perltidy to clean it up a bit. You could do that also, and re-post, if you are so-inclined.

Update: I believe you should call $twig->parsefile() immediately after you call the twig constructor (new()), not near the end of your foreach loop.


In reply to Re: Returning the right results, but at the wrong time from subroutines by toolic
in thread Returning the right results, but at the wrong time from subroutines by leighgable

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.