From: Brian Candler Date: 2011-05-18T17:14:43+09:00 Subject: Re: Linux utility with reverse index facility? unknown wrote in post #998974: > awk &stuff can "give me the the Nth element", > but, without writing your own search-loop, > what can "give me the index of the 'element' > which is " ? > > I think it's called 'reverse indexing' ? > > == TIA. >> a = ["foo","bar","baz"] # note: indexes are 0,1,2 => ["foo", "bar", "baz"] >> a.index("bar") => 1 >> a.grep(/ba/) => ["bar", "baz"] >> a.each_with_index.select { |line,n| line =~ /ba/ } => [["bar", 1], ["baz", 2]] -- Posted via http://www.ruby-forum.com/.