Well, whether or not your data and your intended edit are really as simple as you think they should be, some of your code gives me the impression that you are missing a few details about syntax involved with regular expressions. In particular:
$orgtext = Whey; # this one right here $newtext = Popcorn;
The above works. I reduced it to it's simplest form as a sanity check. Then I tried:
$orgtext = /[Ww]hey/; # this one right here $newtext = Popcorn;
The second statement for "$orgtext" is equivalent to:
$orgtext = ( $_ =~ /[Ww]hey/ );
If nothing was ever assigned to $_ at the time your second $orgtext statement executed, you get the warning because perl is doing a regex match on $_, and $_ is undefined because no value has been assigned to it.

Maybe that second example should have been something like this?

$orgtext = qr/[Wwhey]/;

As for what you "eventually want to try":

$orgtext = /<form[.*]?*\/form>/; # this one right here $newtext = bloc +k;

That assignment to $orgtext has not only the same problem cited above (use "qr/.../" instead?), but also problems with improper use of the square brackets, period, question mark and asterisks. I think what you intended was something like this:

$orgtext = qr/<form.*?\/form>/sg; # s is needed so that "." matches ne +wline

But as others have pointed out, an HTML parsing module, once you get the hang of it, is probably a better approach.

Next there's this in your "base code":

$intext =~ s/$orgtext/$newtext/ms; # the ms is for coping correctly with newlines (that can easily appear + in a binary). ... # replaces ALL occurrences of orgtext with newtext and places the numb +er of occurences in $count
The comment about "that can easily appear in a binary" makes no sense, and the use of "m" on that substitution is actually pointless -- it would be relevant if you were anchoring the regex match with "^" or "$", because "m" alters the behavior of those anchors, but you're not using them. (The "whey" example doesn't use "." either, so the "s" is pointless as well in that case, but it's harmless, and I know you eventually expected to use ".")

And then, based on your closing comment (which refers to a "$count" variable that doesn't appear anywhere), it looks like you should have used the "g" modifier on that substitution, so that all occurrences of "$orgtext" would be changed to "$newtext".


In reply to Re: How to use a regex to parse html form tags by graff
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.