IO#gets with regex

M

Morris Brodersen

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
 
S

Sebastian Hungerecker

Morris said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top