in reply to switching two columns under conditions

Let me suggest Perl, as this site is mostly about Perl.

I would assume most of the syntax you would use is found in your course material, but also in perlsyn. Personally, I would look at perlrun and use the "autosplit" parameter, together with push and print, and the if statement.