From: Robert Klemme Date: 2003-09-19T00:14:34+09:00 Subject: Re: Why IO#readlines does'nt accept a Regexp? "Peter" schrieb im Newsbeitrag news:Pine.GSO.4.10.10309181322340.2343-100000@iris.cs.kuleuven.ac.be... > > Just a guess: normally it's not necessary and another reason might be > > performance, since the overhead of a regexp might be significant for large > > files. > > Another guess... For what I know of regexps, it's that the are compiled to > a finite state machine. This compilation is more expensive than the actual > use since an FSM only considers each input character once. The only point > in splitting at newlines is that newlines tend to occur more frequently > than a random regexp match. BTW, what I meant by more expensive is in > terms of complexity, i.e., execution time as a function of the size of the > input. If your file is large enough, the compilation of the regexp will > become negligable since the regexp is small and the file is big. A totally different reason might be that ruby regexp interface is not suitable for streaming input. I don't know about the C internals but from Ruby you have to provide a String, i.e. a sequence with known length. This is different from providing an interator that just hands out a char at a time. robert