rio-editing on-the-fly

W

Wybo Dekker

according to the rio-docs I would expect it to be possible to edit a file
on-the-fly; for example, I tried to make a copy of /etc/passwd with my own
name (wybo) replaced with XXXX:

rio('/etc/passwd').gsub(/wybo/,'XXXX') > rio('new')

but the resulting file "new" is an exact copy of /etc/passwd.
What am I doing wrong?
 
G

Gavin Sinclair

Wybo said:
according to the rio-docs I would expect it to be possible to edit a file
on-the-fly; for example, I tried to make a copy of /etc/passwd with my own
name (wybo) replaced with XXXX:

rio('/etc/passwd').gsub(/wybo/,'XXXX') > rio('new')

but the resulting file "new" is an exact copy of /etc/passwd.
What am I doing wrong?

You're not reading the file. Try

rio('/etc/passwd').read.gsub(/wybo/,'XXXX') > rio('new')

Perhaps there's a better suggestion?

Gavin
 
W

Wybo Dekker

You're not reading the file. Try

rio('/etc/passwd').read.gsub(/wybo/,'XXXX') > rio('new')

that helped indeed, thanks, but is it not in contradiction to rio's
description of sub?:

sub(re,string)

Create a new Rio referencing the result of applying String#sub to the
value returned by Rio#to_s. So:

ario.sub(re,string)

is equivelent to

rio(ario.to_s.sub(re,string))
 
G

Gavin Sinclair

Wybo said:
that helped indeed, thanks, but is it not in contradiction to rio's
description of sub?:

sub(re,string)

Create a new Rio referencing the result of applying String#sub to the
value returned by Rio#to_s. So:

Now you've just gotta double check what Rio#to_s does :)

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

Forum statistics

Threads
474,197
Messages
2,571,041
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top