Hi again. So far I've been able to take the source code from a website and successfully got the entire thing on one line. The line contains ordered lists of questions and answers, separated by <li> and </li> tags. How would I go about saving the questions into an array, and the answers in a separate one? I tried:

$line =~ s/\n+/ /g; #puts line on one line my @questions; while ($line =~ s/<ol> <li> (.*?) <\/ol>//s) { push @questions, $line; } my @answers; while ($line =~ s/<li>\s*(.*?)\s*<\/li>//s) { push @answers, $line; }

I'm really new to the language and to scripting in general so I apologize in advance for being so terrible at it. I've tried to read books and online resources, but I tend to learn best by examples to "see how it works." If this is the correct way to do it, how do I print out the questions array? I tried a foreach loop where I print print "$_"; but it didn't work. Any help is greatly appreciated, thanks!

UPDATE!! Thanks to you monks, I've been able to successfully save an entire quiz into an array! Now, I'm trying to divide them up into questions and answers. The pattern is basically like this:

Question? Answer.
Some of them are Question as a statement. Answer
And the last type of question is either a Question or Statement, but with the answer in <pre> tags.

I'm hoping that by updating my thread it bumps it up, I don't want to flood the site with similar questions.


In reply to Help with the push function by mistamutt

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.