Is there any reason you're using your own code rather than standard CPAN XML modules? XML::Parser is good for creating flexible XML parsing code, and XML::Simple is great if you want to convert XML into Perl data structures.

To answer your questions:

1. It's always a good idea to pass data rather than referring to it directly to reduce the number of global variables. This makes your code more scalable.

2. You're missing a / from the closing divriskgrade tag. Why have you offered a hint, though? Can you already answer this question? If so, why ask it? If you were to use standard XML modules, they would report where the error occurs.

3. 4. & 5. Why can't you answer these questions yourself? Run the code and find out! For question 5, though, you'd be much better off using CPAN modules such as HTML::Parser instead of writing your own HTML parsing code which is liable to failure.

As for good Web sites that discuss Perl and XML, search Google for perl xml or learn how to find information on Perl Monks. Super Search is very useful. Tutorials and Module Reviews contain information that will help you with XML parsing.

If you're not sure why writing your own parsing code is a bad idea, take a look at Re: Parsing HTML and (tye)Re: parsing HTML.

Update: We've been discussing this thread on the CB, and several monks let me know they have downvoted this post because it answers a homework question. I've considered editing my response to question 2, but the questioner has probably read it by now, and the response might help someone else. Overall, I think my answers were vague enough to make the questioner think, and might be useful to others.


In reply to Re: Perl with XML by tomhukins
in thread Perl with XML by Anonymous Monk

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.