Perl300 has asked for the wisdom of the Perl Monks concerning the following question:
Please forgive me for asking something that might be very simple. I have a string variable $form_dump that is bascially the output of $query->Dump; from a html form submit. So everything in the form is taken into this string variable, which is a multiline variable. The contents of it look like:
<ul> <li><strong>site_user</strong></li> <ul> <li>user1</li> </ul> <li><strong>compare_hidden</strong></li> <ul> <li>average_speed_answer 25 60 30 60 ^M<br /> calls_waiting 300 500 300 500 ^M<br /> many more rows here post_ivr_calls_handled Wisconsin 50 100 50 100 ^M<br /> post_ivr_calls_handled Wyoming 50 100 50 100 ^M<br /> </li> <li><strong>calls_waiting_good_high</strong></li> <ul> <li>300</li> </ul> <li><strong>calls_waiting_warning_low</strong></li> <ul>
What I am trying to do is to get each line between fourth pair of <li> & </li> and put those lines in an array. So far I have tried:
if ( $form_dump =~ m{(<li>)(.*?)(</li>)}s ) { my $inside_li = $2; print $fh "Value of \$inside_li: $inside_li \n"; }
This gives the text between first pair of <li> & </li> which is <strong>site_user</strong>.
Can I get some clues on how to skip the first three pairs of <li> & </li> and and then stop after text between fourth pair is pulled. I had tried something like $form_dump =~ m{(<li>)(^average_.*?)(</li>)}s in an attempt to get only that text which starts with "average_" but it doesn't match anything and $inside_li prints blank.
I am doing something wrong or missing something there.
Update: Updated subject line to mark solved.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Query about regular expression (HTML Parser)
by jeffa (Bishop) on Sep 23, 2015 at 23:49 UTC | |
by Anonymous Monk on Sep 24, 2015 at 00:08 UTC | |
|
Re: Query about regular expression
by ww (Archbishop) on Sep 23, 2015 at 22:12 UTC | |
|
Re: Query about regular expression
by Anonymous Monk on Sep 24, 2015 at 00:35 UTC | |
|
Re: Query about regular expression
by Perl300 (Friar) on Sep 24, 2015 at 15:36 UTC |