1.) Is my basic model okay, slurping the whole file into a variable? or 2.) Should I use a while <> structure?

That depends on the size of your file. If it's large, you might want to use the while() loop.

And even when I do get the simple Whey replaced with Popcorn - it only does the first instance, basically, I am guessing, because there is no iterative code in this script.

The iterative code you're looking for is a /g on the end of your s///.

However, that answer isn't going to solve your problems. If you want to eat non-mushy cereal, you need to put your dentures in. Use perl's dentures at the top of your code:

use strict; use warnings;

Finally, your eventual replacement pattern, /<form[.*]?*\/form>/ is flawed, and will not do what you appear to think it will do. The square brackets, [], indicate a character class, so what you're matching is <form, followed by either a literal . or a literal *, or nothing, followed by /form>.

The regex you are looking for(*) is m{<form.*?</form>}. Note the use of an alternative delimiter so the / doesn't need to be escaped.

(*) You are not looking for a regex, which are insufficient for parsing gobs of HTML/XML. The regex given above already has problems. :)

Cheers,


In reply to Re: How to use a regex to parse html form tags by ammon
in thread How to use a regex to parse html form tags by monkeriffic

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.