in reply to switching parts of a text

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 ;-)

Replies are listed 'Best First'.
Re^2: switching parts of a text
by oblate kramrdc (Acolyte) on Sep 14, 2006 at 21:26 UTC

    WOW!
    That was short! Thanks Tanktalus!