csvReader read file byLine()?
Jens Mueller
jens.k.mueller at gmx.de
Fri Jun 22 07:44:56 PDT 2012
Jesse Phillips wrote:
> On Friday, 22 June 2012 at 08:12:59 UTC, Jens Mueller wrote:
> >The last line throws a CSVException due to some conversion error
> >'Floating point conversion error for input "".' for the attached
> >input.
> >
> >If you change the input to
> >3.0
> >4.0
> >you get no exception but wrong a output of
> >[[4], [4]]
> >.
>
> Yes, and it seems .joiner isn't as lazy as I'd have thought.
> byLine() reuses its buffer so it will overwrite previous lines in
> the file. This can be resolved by mapping a dup to it.
>
> import std.stdio;
> import std.algorithm;
> import std.csv;
>
> void main()
> {
> struct Record {
> double one;
> }
> auto filename = "file.csv";
> auto file = File(filename, "r");
> auto input = map!(a => a.idup)(file.byLine()).joiner("\n");
> auto records = csvReader!Record(input);
> foreach(r; records)
> {
> writeln(r);
> }
> }
Thanks. That works. But this should be either mentioned in the
documentation or fixed. I would prefer a fix because the code above
looks like a work around. Probably byLine or joiner then need some
fixing. What do you think?
Jens
More information about the Digitalmars-d
mailing list