--- Marko Schulz <in6x059 / public.uni-hamburg.de> wrote:
> On Mon, May 13, 2002 at 10:37:50PM +0900, Berger, Daniel wrote:
> > 
> > I'm looking for a way to modify a file inline without using a
> temp file.  I
> > want to do this within code, not on the command line (and no, I'm
> not
> > interested in 'system' calls either).
> > 
> > All I'm really trying to do is a unix2dos type operation.  Easy
> enough with
> > temp files, I realize, but I'm stubborn. :)
> 
> I never did it in Ruby, but if the feature is implemented similar
> to Perl, than something along this lines should work:
> 
>   def unix2dos(filename)
>   argv=ARGV
>   ARGV=[filename]
>   $-i = ".bak"
> 
>   while gets
>      gsub(/\n/,"\r\n");   # Or is Newline on Dos \n\r?
>   end
> 
>   ARGV=argv
>   end
> 
> Maybe it works. :-)
> 
> I also do not know how to revert the effect of setting $-i. By
> setting
> it to nil?




Do note that in perl, a temp file is still used (behind the scenes)
even if you have the "-i" feature set to not save a temp file.

The original query specified no temp file; I don't know if he meant
one was strictly not allowed at all at any time, one wouldn't be
automatically saved for you, or that the programmer wasn't allowed to
explicitly create one.

=====
--
Yahoo IM: michael_s_campbell

__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com