Limbering Up: Comma-Delimited Data
Vector 17:2, page 31
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:
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:
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