Tuesday, October 23, 2007

[Protium] Splitting

Here's a short script for splitting a file. The file in this case is the perl language data file from the PLEAC website. pleac_perl.data contains sections marked with "# ^^PLEAC^^_" followed by a number. The section applies until the next section is marked. The script splits each section out of pleac_perl.data into pleac_perl_number.p. I'm working through these files and re-expressing the intent of the perl code in Protium.

The code may be described as follows:
  1. Define a work area, or alias, for the data file, calling it 'pleac'.
  2. Open the text file within that work area, using define-file-lit.
  3. Start a loop which iterates through an enumeration of the lines of data in the work area.
  4. Let a variable contain the data in the current line of the work area.
  5. Test whether the regular expression works for the current line.
  6. If it does work, let a variable contain the number found, ...
  7. ... turn off any output redirection, ...
  8. ... and redirect output to the file 'pleac_perl_' + the number found (in the same directory as the script).
  9. End of the if.
  10. Output the contents of the line.
  11. End of the iteration.
Simple ... and way powerful!

© Copyright Bruce M. Axtens, 2007


Anonymous said...

Except for the syntax, this doesn't seem any simpler or more powerful than the equivalent written in python or perl.

Anonymous said...

This is not simple and powerful. It's a retarded piece of incomprehensible babble.

Why don't you wake up from your drug-induced stupor and check out how this kind of completely trivial task is done in any of the modern, popular scripting languages.

Or even not so modern. A solution in the Unix language awk would be much nicer. Heck, sed.