From: "Rebhan, Gilbert" Date: 2007-05-15T21:49:22+09:00 Subject: Re: slow file access with mapped drives ?! Hi, -----Original Message----- From: Robert Klemme [mailto:shortcutter@googlemail.com] Sent: Monday, May 14, 2007 3:51 PM To: ruby-talk ML Subject: Re: slow file access with mapped drives ?! /* I was referring to the fact that you present one bit of code and in your answer to my posting you present another bit of code as if *that* was the original code. */ sorry for that Thanks for your annotations !! > IO.popen("#{config['CVSEXE']} -d > :pserver:#{cvsuser}:#{cvspass}@cvsprod:d:/cvsrepos/#{x} login") > } /* Why do you use popen if you do not read the pipe? *If* you use popen you should make sure the pipe is read from - even if you ignore what you find because otherwise the other process might get blocked. */ now i have = system(...) instead >Why do you use "#{@cvsreg}" instead of plain @cvsreg or @cvsreg.to_s? assuring a string, but @cvsreg works > config['targetdirs'].each do |dir| > puts "\n\n" > Find.find(dir) do |f| > if f =~ /#{config['targetfilepattern']}/ >You should pull out this regexp compilation from both loops for more >efficiency. OK, now i have = s=config['replaceto1']<<@cvsreg< else > puts "\n\nDone !!" > sleep 1 /* Why the sleep? */ to see the echoes on stdout, before they disappear > replacefrom: ".*" /* This pattern will kill you if there are two sections with in the file. You should at least use the reluctanct qualifier. */ i know, it's dangerous, but there's no other match in the file for sure /* > replaceto1: " replaceto2: "]]>" This cries for using a regexp group. Also filesed is pretty inflexible. I'd rather do something like this: def file_replace(file, tmp = file + Time.now.usec.to_s) File.open(tmp, "w") do |out| File.open(file) do |inf| inf.each_line {|line| out.puts(yield(line)) } end end File.mv(tmp, file, :force => true) end Now you can do arbitrary line based replacements like file_replace "foo.txt" do |line| "# " << line end */ Sorry don't understand how your code works and also there is no regex stuff in it ?! I thought there would be an easy xml/xpath solution for my needs, as i have to edit a xmlfile, i tried with REXML = >> require 'rexml/document' => true >> include REXML => Object >> file=File.new("Y:/tempwork/ScmConfig.xml") => # >> doc=Document.new file => ... >> cvspass = XPath.match( doc, "//de.foobar.scm.repository.repcvs.CvsConnector/Passwort") => [ ... ] i tried several combinations of = >> cvspass[1].gsub(/(!\[CDATA\[)\.*(\[\[>Passwort>)/, $1.to_s<<'test123'<<$2.to_s) NoMethodError: private method `gsub' called for nil:NilClass >> cvspass[1].gsub(/(!\[CDATA\[)\.*(\[\[>Passwort>)/, $1<<'test123<<$2) NoMethodError: undefined method `<<' for nil:NilClass what's the right method/syntax with REXML ? Regards, Gilbert