[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Why IO#readlines does'nt accept a Regexp?

Peter

9/18/2003 11:30:00 AM

1 Answer

Robert Klemme

9/18/2003 2:52:00 PM

0


"Peter" <Peter.Vanbroekhoven@cs.kuleuven.ac.be> 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