in reply to Re^2: Help with the push function
in thread Help with the push function

I tried to push @questions, $1 but it still isn't printing anything when I...

There's no mention of "push" in the code snippet following that statement, so we don't know what "tried to push @questions, $1 really means in this context. To recap the discussion so far: first you present some code, but no data, then some data (with a different problem) but no code. Dude, we cannot see the things in your head, or the things you see on your terminal but don't show us. Please try harder to be coherent.

The HTML document I'm trying to write this for is rather simple. It's a ordered list of quiz questions, followed by answers like this:

"Rather simple" seems apt for describing the markup (though it actually looks like it'll be prone to unpredictable variability) But the information content -- esp. the "Statement. Response to statement." case -- is only simple for human readers who know the language well enough that they can easily figure out which periods mark sentence boundaries (and which ones don't), and can tell the difference between a "statement" and a "response to a statement." (And BTW, have you noticed that sometimes an "answer" to a "question" contain another question?)

You don't say how much data of this sort you have to deal with, but if it gets to more than several dozen "statement. response." type cases, you can expect some edge cases that may need to be resolved by a human editor.

If you get acquainted with something like HTML::Parser or HTML::TokeParser, you'll have an easier time dealing with variable mark-up, so you can focus on the harder problem of parsing the information content (where the essential division you need to find might not be marked in any consistent or explicit way).

In pseudo-code terms, you probably want something like:

# setup the parser to capture the contents of all <li> chunks into @ar +ray, then foreach ( @array ) { if ( m{(.*?)<pre>(.*)</pre>}s # NB: "?" makes ".*" non-greedy or /(.*\?)\s+(\S.*)/s # NB: "\?" matches a literal qmark or /^([^.]+)\.\s+([^.]+\.)\s*$/s ) { push @questions, $1; push @answers, $2; } else { # you have a harder case to solve (might need a human) } }
If you have trouble with that, it'll be okay to start a new thread -- it'll be something other than "help with the push function"...

(updated last code snippet to correct a mistaken comment about "?")