On Mon, 14 May 2012 10:41:54 +0200, Christian Köstlin
<christian.koest...@gmail.com> wrote:
Hi,
i wanted to output an ascii-file line by line, but reversed.
the idea was to open the file, use byLine to read it line-by-line, make
this range an array, and retro this array.
But when i convert byLine to an array, the result is already trash.
Please see this snippet.
import std.stdio;
import std.array;
int main(string[] args) {
if (args.length != 2) {
throw new Exception("Usage: " ~ args[0] ~ " file1");
}
auto f = File(args[1], "r");
auto i = array(f.byLine());
foreach (l; i) {
writeln(l);
}
return 0;
}
Any idea why this happens?
regards
christian köstlin
I believe byLine reuses the internal buffer. Try duping the lines:
auto i = f.byLine().map!"a.idup"().array();