Hello monks,

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.


In reply to [Solved]: Query about regular expression by Perl300

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.