"Mike Wilson" <wmwilson01 / hotmail.com> wrote in message news:F1792JB1ndcx3Vp20N300003b1a / hotmail.com... > > > > >#!/usr/local/bin/ruby -pi > >BEGIN { > > $searchString = ARGV.shift > > $replaceString = ARGV.shift > >} > >gsub($searchString,$replaceString) > > > > I'm curious as to why the BEGIN block is used here? Also, seeing as there's > no error checking or anything, and you're assuming arguments, why not: > #!/usr/local/bin/ruby -pi > gsub(ARGV[0], ARGV[1]) > Your code might make following error message. $ ./sr.rb foo bar tmp* ./sr.rb:8: No such file or directory - "foo" (Errno::ENOENT) > For this, I'd probably just do > $ /usr/local/bin/ruby -pi -e 'gsub(foo, bar)' somefile > > Shortest but a little ugly compared with $ ./sr.rb foo bar somefile > > Mike Wilson > Unix Administrator > http://ruby.weblogs.com > Hee-Sob Park.