I’m trying to figure out why the following code chunk fails to edit my
file in-place:
$-i = ‘.foo’ # set in-place edit mode
mf = File.open(‘Makefile’, ‘r+’)
mf.each_line do |line|
line.sub!(/-l$(RUBY_INSTALL_NAME) /, “”)
end
mf.close
Any ideas?
Ian
···
–
Ian Macdonald | Life is like an onion: you peel off layer ian@caliban.org | after layer and then you find there is
> nothing in it. – James Huneker
>
>
I didn’t find anything in the documentation to suggest that it only
works on ARGF, so it would have taken me a very long time to figure
that out.
Ian:
It’s under ‘Command-Line Options’ on page 138 of the Pickaxe:
Edits ARGV files in place. For each file named in ARGV, anything you
write to standard output will be saved back as the contents of that
file. A backup copy of the file will be made if extension is
supplied.
I didn’t find anything in the documentation to suggest that it only
works on ARGF, so it would have taken me a very long time to figure
that out.
Ian:
It’s under ‘Command-Line Options’ on page 138 of the Pickaxe:
Edits ARGV files in place. For each file named in ARGV, anything you
write to standard output will be saved back as the contents of that
file. A backup copy of the file will be made if extension is
supplied.
–
Ian Macdonald | How to Raise Your I.Q. by Eating Gifted ian@caliban.org | Children – Book title by Lewis B.
> Frumkes
>