[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

IO#gets with regex

Morris Brodersen

7/14/2008 11:42:00 PM

hi,

in ruby 1.8.7, IO#gets takes a seperator string as argument. i suggest
adding support for a regular expression to match any seperator. this
way, one could check for different seperators like \n\t\0 etc. this is
mainly useful for File IO.

example:
handle = File.open "test.in"
$/ = / \n\t/
str = handle.gets

if there's any other efficient way (other than using IO#getc and read
the file char by char) to achieve the same thing, i'd be happy to know
about it.

-- morris
--
Posted via http://www.ruby-....

1 Answer

Sebastian Hungerecker

7/16/2008 11:17:00 AM

0

Morris Brodersen wrote:
> in ruby 1.8.7, IO#gets takes a seperator string as argument. i suggest
> adding support for a regular expression to match any seperator.

That'd be problematic as its not always possible to accurately apply a regex
to a file (or whatever the IO comes from) without reading the whole file (not
without restrictions on the regex anyway), which would kind of defeat the
purpose of using gets instead of read.