[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Swap contents in two files

Christopher Latif

12/14/2006 1:25:00 PM

I have two files, I want to swap the contents of the files in my
program, suggestions?

--
Posted via http://www.ruby-....

15 Answers

Robert Klemme

12/14/2006 1:27:00 PM

0

2006/12/14, Christopher Latif <christopherl@bredband.net>:
> I have two files, I want to swap the contents of the files in my
> program, suggestions?

Renaming with a third temp file name is the most efficient if you know
that no file handles are open on these files.

robert

--
Have a look: http://www.flickr.com/photos/fu...

Christopher Latif

12/14/2006 2:03:00 PM

0

Robert Klemme wrote:
> 2006/12/14, Christopher Latif <christopherl@bredband.net>:
>> I have two files, I want to swap the contents of the files in my
>> program, suggestions?
>
> Renaming with a third temp file name is the most efficient if you know
> that no file handles are open on these files.
>
> robert

How the code for that program going to look like?


--
Posted via http://www.ruby-....

hemant

12/14/2006 2:20:00 PM

0

On 12/14/06, Christopher Latif <christopherl@bredband.net> wrote:
> Robert Klemme wrote:
> > 2006/12/14, Christopher Latif <christopherl@bredband.net>:
> >> I have two files, I want to swap the contents of the files in my
> >> program, suggestions?
> >
> > Renaming with a third temp file name is the most efficient if you know
> > that no file handles are open on these files.
> >
> > robert
>
> How the code for that program going to look like?
>

How abt:
require 'fileutils'

FileUtils.copy_file("a.exe","b.exe")
FileUtils.mv "a.exe.stackdump","a.exe"
FileUtils.mv "b.exe","a.exe.stackdump"


--
gnufied
-----------
There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.

Ara.T.Howard

12/14/2006 3:08:00 PM

0

dblack

12/14/2006 3:13:00 PM

0

Ara.T.Howard

12/14/2006 3:23:00 PM

0

Robert Klemme

12/14/2006 3:49:00 PM

0

On 14.12.2006 16:23, ara.t.howard@noaa.gov wrote:
> On Fri, 15 Dec 2006 dblack@wobblini.net wrote:
>
>> Hi --
>>
>> On Fri, 15 Dec 2006, ara.t.howard@noaa.gov wrote:
>>
>>> a, b, ignored = ARGV
>>
>> You can also do:
>>
>> a, b = *ARGV
>>
>> (which I know you know but it's just another option for anyone who
>> doesn't want the extra variable :-)
>
> quite right. i've moved to the former because it's self doccumenting : a
> crutch for my feeble mind and almost complete lack of doccumentation
> skills!

I usually use

a,b, = *ARGV

Kind of to be sure... :-)

robert

dblack

12/14/2006 4:27:00 PM

0

James Gray

12/14/2006 4:40:00 PM

0

On Dec 14, 2006, at 9:50 AM, Robert Klemme wrote:

> I usually use
>
> a,b, = *ARGV

Yuck. ;)

James Edward Gray II

Tom Werner

12/14/2006 4:48:00 PM

0

Christopher Latif wrote:
> I have two files, I want to swap the contents of the files in my
> program, suggestions?
>
>

Why not just rename the files? Or am I missing your meaning?

Tom