From: "酵費七(Park, Hee-Sob)" Date: 2001-02-04T16:10:07+09:00 Subject: [ruby-talk:10339] Re: Efficiency Check Hi, "Jason" wrote in message news:95iage$8n$1@nnrp1.deja.com... > Hi All, > > Below is a directory wide (or file wide, depending on your preference) > search and replace method, written in Ruby. Just so I know I'm on the > right track, is that the quickest way to write the application (ie, is > there a shortcut around creating an object named aFile, and then > writing to the file? > > > def sr(searchString, replaceString, fileName) > if File.stat(fileName).file? > aFile = File.open(fileName, "r").read.gsub(searchString, > replaceString) > File.open(fileName, "w").print(aFile) > end > end > (ARGV.length - 2).times { |i| sr(ARGV[0], ARGV[1], ARGV[2+i])} > How about this? #!/usr/local/bin/ruby -pi BEGIN { $searchString = ARGV.shift $replaceString = ARGV.shift } gsub($searchString,$replaceString) > Jason >