Skip to content

Limbering Up: Comma-Delimited Data

Vector 17:2, page 31

programming techniques data and files

Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 31

When working with data from “external” (non-APL) applications, you need the ability to accept the data in a form comprehensible to both parties (you and them). One such form is the “comma-delimited file.” The values in a comma-delimited file are separated by commas. The records are typically separated by a newline character (carriage return).

Here’s a sample:

26,154.25,Fred
722,14.95,Jane
17,0,Bob

Each of these records contain three values of “fields” of information.

Here’s your task: Given a comma- and newline-delimited character vector (newline at the end of each record), return a character matrix with the values realigned so they may be readily extracted via column-indexing. Like so:

26 154.25Fred
72214.95 Jane
17 0     Bob

The function (call it COMMA∆MAT) should also return the global integer vector fieldwidths to tell you how wide the realigned fields are (3 6 4 in this case).

Write the fastest COMMA∆MAT you can muster and mail your solution on paper or APL*PLUS PC or APL*PLUS II disk to:

Vector Production
Brook House, Gilling East
YORK YO62 4JJ UK


Reprinted with kind permission from Zark APL Tutor News, a quarterly publication of Zark Incorporated, 23 Ketchbrook Lane, Ellington, CT06029, USA