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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |