in reply to Swap Input lines

When testing code like this (for homework or otherwise...) sometimes it helps to start by creating very simple “proof of concept” programs that build-up to the final deliverable.   In other words, writing two throw-away programs:

  1. One that simply reads from a disk file and prints it out line-by-line.
  2. Another one that doesn’t read from a disk file at all, but rather tests the code that you intend to use to separate “a particular string” into its component parts.

In the second case, have a look at (for instance) Test::More.   I’m not talking so much about “this particular module or its many brethren,” but rather the approach; the strategy; the philosophy.   Small, focused test-cases (whether built using that module or not) which fully exercise the code that you have written.   For instance, the splitting code needs to be able to handle at least all of the following input data:   (quote-marks are not part of the data)

When that particular segment of code can be thoroughly and completely tested in isolation, and passes all such tests, then you know that you can put your full body weight upon that section of code and move forward.   While it may sound strange to “go to all of that trouble” for what may well be homework, believe me, it’s worth it.

Design and build every piece of software from the bottom up, using pro-actively tested components that are tested at the earliest possible opportunity and at every subsequent stage of integration.   Even homework.