problems with DPL example.

Shripad K assortmentofsorts at gmail.com
Tue Mar 13 08:39:27 PDT 2012


Boy its really hard to navigate this forum for an old thread.
Seems like a lot has changed in D since this thread. Here is the 
correct snippet if someone comes searching for "error: undefined 
identifier splitter" like me :) (using DMD64 D Compiler v2.058)

import std.stdio, std.string, std.algorithm;

void main() {
	ulong[string] dictionary;
	foreach(line; stdin.byLine()) {
		foreach(word; splitter(strip(line))) {
			if(word in dictionary) continue;
			auto newID = dictionary.length;
			dictionary[word.idup] = newID;
			writeln(newID, '\t', word);
		}
	}
}

On Wednesday, 12 October 2011 at 15:39:14 UTC, Steven 
Schveighoffer wrote:
> On Mon, 10 Oct 2011 15:42:26 -0400, simendsjo 
> <simendsjo at gmail.com> wrote:
>
>> On 10.10.2011 21:38, bearophile wrote:
>>> %u:
>>>
>>>> D>echo hello | wordcount2.exe<  wordcount2.d
>>>> 0       hello
>>>> std.stdio.StdioException at std\stdio.d(2156): Bad file 
>>>> descriptor
>
> This is a bug in the C runtime that D uses, where pipes are not 
> used correctly.  I'm working on getting Walter to fix it as 
> it's needed for the new std.process as well.
>
>>>
>>> Try:
>>>
>>> wordcount2.exe<  wordcount2.d
>>>
>>> Bye,
>>> bearophile
>>
>> Shouldn't the original way work too?
>
> Yes, but the main difference is, bearophile's method simply 
> opens a file, which FILE * obviously supports no problem.  Your 
> method creates a process with a pipe as the input.
>
> -Steve



More information about the Digitalmars-d-learn mailing list