On 23/04/2016 10:40 PM, salvari wrote:
Hello all!

I'm trying to read a csv file (';' as separator) with very long lines.

It seems to be really simple, I read the columns name with no problem.
But as soon as the program parses the first line of data, the array
containing the columns names seems to be overwrited.

I'm using dmd: DMD64 D Compiler v2.071.0

My code:

import std.stdio;
import std.algorithm;
import std.array;

char[][] columns;


void main() {
  LINE:foreach(line; stdin.byLine()){
     if(line.startsWith("Interfaz")){
       writeln("IN HERE");
       columns = line.split(";");
       writeln(columns);               // Everything seems to be ok
       continue;
     } else{
       auto linedata = line.split(";");
       writefln("My line: %s", line);        // Fine.
       writefln("LineData: %s", linedata);   // Fine. Line data is ok
       writefln("Columns: %s", columns);     // Wrong!!! columsn array
                                             // contains garbage data
                                             // from linedata
     }
   }
}

Its probably using a buffer.
columns = line.dup.split(";");
Should fix it.

Reply via email to