tabular

Loads a delimited text file, line-by-line, parses the line into fields, and calls a delegate/function for each line.

void
tabular
(
Members
alias storeFunction
char delimiter = '\t'
)
(
const string filename
)

Return Value

Type: void

On success, the function returns nothing (void), the call back function have been called for every line.

Throws

std.std.exception.Exception. on failure to correctly parse a line. std.std.file.FileException. on I/O failures.

Examples

// Load a text file with three numeric columns,
// Store the tuple in an array
// (NOTE: this is a naive, inefficient way to populate an array, see NOTES)
alias Tuple!(int,int,int) T;
T[] t;
tabular!( T,		   // The number and types of the (expected) fields in the file
delegate(x)
{ t ~= x; }, // for each line read, call this function. X will be of type T.
'\t'		 // The delimiter (default = TAB)
)("file.txt"); // The file name to read.
// Load a text file with three numeric columns,
// Use the second column as a KEY and the third column as the VALUE.
alias Tuple!(int,int,int) T;
int[int] data;
tabular!( T,			  // The number and types of the (expected) fields in the file
delegate(x)
{   // for each line read, call this function. X will be of type T.
data[x[1]] = x[2] ;
},
'\t'			 // The delimiter (default = TAB)
)("file.txt");	// The file name to read.

Notes: $(OL

  • See parseDelimited for details about parsing the delimited lines of the fiile
  • $(LO )

    TODO: Make this an InputRange

    Meta