From: Martin Weber Date: 2003-06-04T10:25:58+09:00 Subject: Re: case of sub! not working On Wed, Jun 04, 2003 at 10:14:28AM +0900, Ian Macdonald wrote: > On Wed 04 Jun 2003 at 04:39:44 +0900, Michael Campbell wrote: > > > > I'll take a stab at it. I can't promise that > > > what I say is correct. > > > > I gotcha. Ruby is doing this to avoid having to track the actual > > changes to the string (outside of changes to ENV), and/or dealing > > with copy-on-write semantics. > > > > Interesting; thanks. > > In my program, however, I would have been quite happy to have sub! just > modify the copy of ENV['PATH'] that it had made, as I wanted to modify > the path that would be used to find the location of a binary I was about > to open with popen. I wasn't trying to modify the outside environment, > just that of my script and any of it children. Which again needs the setenv() call to actually alter the value in the environment. and it did modify the copy of ENV['PATH'] it made, but it didn't propagate it back to ENV :) ENV['bla'] = "banzai" `echo $bla` # <-- banzai\n x=ENV['bla'].sub!(/banzai/, "ayaken") # here the copy is modified, result => x `echo #{x}` # <-- ayaken\n <<- see, it did modify the copy `echo $bla` # <-- banzai\n <<- but no setenv() call. -martin