From: dblack@... Date: 2007-01-03T08:30:09+09:00 Subject: Re: Delete line from file Hi -- On Wed, 3 Jan 2007, William James wrote: > > Jules wrote: >> Hi, >> >> Given a line number, what is the best way to delete this line from a >> file? >> >> And given an array of line numbers, what is the best way to delete >> these lines from a file? >> >> Thanks, >> >> Jules > > lines = IO.readlines('junk1') > [1,3,5].each{|n| lines.slice!(n) } That's going to have a side-effect problem: irb(main):004:0> a = %w{ a b c d e f } => ["a", "b", "c", "d", "e", "f"] irb(main):005:0> [1,3,5].each {|e| a.slice!(e) } => [1, 3, 5] irb(main):006:0> a => ["a", "c", "d", "f"] You'd probably want to reverse the list of indices. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)