On Sunday, 26 February 2017 at 21:50:38 UTC, Jordan Wilson wrote:
auto readNumMatCsv2 (string filePath, string ndv, string new_ndv){
    double[][] p_numArray;
    try {
        auto lines = File(filePath,"r").byLine;
        lines.popFront; // get read of header
        p_numArray = lines.map!(a => a.replace (ndv,new_ndv)
                                      .splitter (",")
                                      .map!(a => a.to!double)
                                      .array)
                          .array;
    } catch (Exception e){
e.msg.writeln; // this replaces "Could not read file. Quit here."
    }
    return p_numArray;
}

It took me quite a while to get the whole usage of range stuff like "map" and "filter" etc., but I think it's worth the effort.

This looks like more friendly readable compact code, where should be the goal. Thanks for your insights!

Reply via email to