From: Paul van Delst Date: 2006-11-30T09:05:10+09:00 Subject: Re: Need a range, but not getting it. . . . Peter Bailey wrote: > Rimantas Liubertas wrote: >>>> Your problem was that, although gsub! (with the !) normally modifies the >>>> receiver, 'files' wasn't the receiver (to_s was), so you weren't actually >>>> changing 'files'. >>> Not correct. Try it. >>>> files=["im123000-im123006"] >> => ["im123000-im123006"] >>>> files.to_s.gsub!(/-/,'..') >> => "im123000..im123006" >>>> files >> => ["im123000-im123006"] >> >> >> Regards, >> Rimantas > > Thanks. But, I'm trying to design this script for users to put in > arguments. (It's an image modification script that ftps named files > from one server to another.) So, a user might type in: test1.rb > im123456-im123459 im123462 im123466 I had a similar need recently in that I wanted to specify ranges and individual numbers. I chose the input syntax as 3-10,14,24,26-28 type of thing. What about this?: irb(main):016:0> class String irb(main):017:1> def parse_range #(str) irb(main):018:2> sa=[] irb(main):019:2> self.split(",").each do |s| irb(main):020:3* if s=~/([\w\d]*)-([\w\d]*)/ irb(main):021:4> sa << ($1..$2).to_a irb(main):022:4> else irb(main):023:4* sa << s irb(main):024:4> end irb(main):025:3> end irb(main):026:2> pr=sa.flatten.uniq irb(main):027:2> end irb(main):028:1> end => nil irb(main):029:0> input => "im123456-im123459,im123462,im123466" irb(main):030:0> input.parse_range => ["im123456", "im123457", "im123458", "im123459", "im123462", "im123466"] Not exactly the same input syntax as you have suggested you want, but close. cheers, paulv -- Paul van Delst Ride lots. CIMSS @ NOAA/NCEP/EMC Eddy Merckx