What you probably want is something using Parse::RecDescent. But that's beyond my skill, so if you're claiming to be "still learning PERL" then it may not be what you want, either. Or, if it is, I can't help ;-)

You may want to make a few changes, and learn a bit more about the substitution operator in perlre. For example, instead of doing this in a huge if/elsif block, you can take advantage of the fact that if the s operator doesn't find the first regular expression in the line, it won't do anything. And it will return false.

s/^\s*MOVE\s+(\S+)\s+TO\s+(\S+)\s*\./$2 := $1;/ and next; s/^\s*DISPLAY\s+'(.*)'\./PUT("$1")/ and next; s/^\s*DISPLAY\s+(.*)\./PUT($1)/ and next; ++$discarded;
Note that I do the check with the quote before the check without the quote - because the one without the quote will match with quotes, too.

Hope that helps,

Update: The above merely changes the value in-place. You'll need to copy the value to your output. It's easier if you don't care about the discarded bit ;-)


In reply to Re: switching parts of a text by Tanktalus
in thread switching parts of a text by oblate kramrdc

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.