From: Robert Klemme Date: 2012-11-08T22:35:21+09:00 Subject: Re: Need help improving this FileUtils.cp of an array of destinations --14dae93410d30d2d2104cdfbe8cc Content-Type: text/plain; charset=ISO-8859-1 On Thu, Nov 8, 2012 at 11:08 AM, Peter Hickman < peterhickman386@googlemail.com> wrote: > This is the code you posted > > $files.each_with_progress do | val | > $files.each do |element| > FileUtils.cp("#{$old_home}/#{$sName}", "#{Dir.pwd}/#{element}") > end > end > I do especially wonder what val is used for and why there seem to be two iterations through $files - this is O(n*n). Your description looks contradictory to me: on one hand you say that $files holds destinations and then you say that one file is replaced by 139 files (which would mean $files contain sources). To copy a file into destinations src = File.join old_home, sName $files.each do |dst| FileUtils.cp src, dst end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --14dae93410d30d2d2104cdfbe8cc Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On Thu, N= ov 8, 2012 at 11:08 AM, Peter Hickman <peterhickman386@google= mail.com> wrote:
This is the code you post= ed

$files.each_with_progress do | val |
=A0 =A0$files.e= ach do |element|
=A0 =A0 = =A0 =A0FileUtils.cp("#{$old_home}/#{$sName}", "#{Dir.pwd}/#{element}= ")
=A0 =A0 end
=A0end

I do especially wonder what val is used for and why there seem to = be two iterations through $files - this is O(n*n).

Your description = looks contradictory to me: on one hand you say that $files holds destinatio= ns and then you say that one file is replaced by 139 files (which would mea= n $files contain sources).

To copy a file into destinations

src =3D File.join old_home, sNa= me

$files.each do |dst|
=A0 FileUtils.cp src, dst
end
=A0Kind regards

robert


--
re= member.guy do |as, often| as.you_can - without end
http://blog.rubybestpractice= s.com/
--14dae93410d30d2d2104cdfbe8cc--