AWKward NumGuess implementation

Here’s another silly NumGuess version of the because-I-can kind, this time in AWK. It’s quite a specific language, not designed for writing general purpose programs, but it shouldn’t bother me one bit. In a strange way it fits the NumGuess flow quite well.

The language was designed to easily process lines in a text file. For those of you not familiar with it an AWK  program consists of up to 3 program blocks:

  • BEGIN: called at the beginning of the program, used for adding header and doing initialisation tasks.
  • Main block: called once for every line in a text file.
  • END: called whenever the program ends, used for adding footer or totals.

When calling AWK with no input, it will use the terminal by default, which will give a nice infinite input loop. All I had to do is set some variables to keep the state the program is in and stop processing input whenever the user wants to quit.

Here you have it, enjoy the latest addition to the NumGuess family.

Share Button
Tagged with: , , ,

Leave a Reply