From: Marco Bottaro Date: 2006-05-04T23:16:08+09:00 Subject: Re: Ruby equivalent to simple awk program I keep finding myself iterating and collecting this way. Would you care please to illustrate with an example? Very much appreciated! Cheers, Marco James Gray wrote: > On May 4, 2006, at 8:34 AM, Gregory Seidman wrote: > >> I have gotten pretty good with Ruby and I *can* duplicate this in >> about 10 >> seconds: >> >> input = (ARGV.length>0) ? File.new(ARGV[0]) : $stdin > > If you change that to: > > input = ARGF > > You get the same behavior, but can accept multiple argument files on > the command-line. > >> arr = [] >> input.each_line { |line| arr << line } > > Usually when you iterate and collect like this, it's a sign that you > really want a different method (readlines() or to_a() in this case). > > James Edward Gray II -- Posted via http://www.ruby-forum.com/.