Slurping a file like in Perl

X

Xeno Campanoli

I want to slurp up two files and substitute one file in another for a symbol
in that file's data. In Perl I may simply do this all in memory. Is there a
limit in Ruby string size that prevents this, or is there an easier more elegant
way about it? Thanks

Sincerely, Xeno Campanoli
http://www.eskimo.com/~xeno
 
M

Maik Schmidt

Xeno said:
I want to slurp up two files and substitute one file in another for a symbol
in that file's data. In Perl I may simply do this all in memory. Is there a
limit in Ruby string size that prevents this, or is there an easier more elegant
way about it? Thanks

There was a very interesting article about file slurping on perl.com
some weeks ago: http://www.perl.com/lpt/a/2003/11/21/slurp.html.

Maybe you can benefit from it, because the IO functions that were used
are also available in Ruby. At least you should benefit from the test
suite. I thought about porting this to Ruby but currently I am a bit
short of time. Maybe you want to try it?

Merry christmas,

<maik/>
 
G

Gavin Sinclair

I want to slurp up two files and substitute one file in another for a symbol
in that file's data. In Perl I may simply do this all in memory. Is there a
limit in Ruby string size that prevents this, or is there an easier more elegant
way about it? Thanks

You can slurp a file with File.read(path), and perform a substitution
with String#sub(re, str).

Gavin
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top