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.
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.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;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |