Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4725

Re: Linux utility with reverse index facility?

Path csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!feeder.news-service.com!tudelft.nl!txtfeed1.tudelft.nl!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail
From Brian Candler <b.candler@pobox.com>
Newsgroups comp.lang.ruby
Subject Re: Linux utility with reverse index facility?
Date Wed, 18 May 2011 03:14:43 -0500
Organization Service de news de lacave.net
Lines 22
Message-ID <ada9767bab841a044c9285f78e4b7070@ruby-forum.com> (permalink)
References <iqquq7$i46$1@dont-email.me>
NNTP-Posting-Host bristol.highgroove.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace talisker.lacave.net 1305706864 17251 65.111.164.187 (18 May 2011 08:21:04 GMT)
X-Complaints-To abuse@lacave.net
NNTP-Posting-Date Wed, 18 May 2011 08:21:04 +0000 (UTC)
In-Reply-To <iqquq7$i46$1@dont-email.me>
X-Received-From This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway
X-Mail-Count 383434
X-Ml-Name ruby-talk
X-Rubymirror Yes
X-Ruby-Talk <ada9767bab841a044c9285f78e4b7070@ruby-forum.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:4725

Show key headers only | View raw


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 <elementValue>" ?
>
> 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/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Linux utility with reverse index facility? no.top.post@gmail.com - 2011-05-16 10:38 +0000
  Re: Linux utility with reverse index facility? pk <pk@pk.invalid> - 2011-05-16 11:41 +0100
  Re: Linux utility with reverse index facility? Robert Klemme <shortcutter@googlemail.com> - 2011-05-16 05:45 -0500
  Re: Linux utility with reverse index facility? "Chris F.A. Johnson" <cfajohnson@gmail.com> - 2011-05-16 07:59 -0400
    Re (2): Linux utility with reverse index facility? no.top.post@gmail.com - 2011-05-16 19:30 +0000
      Re: Re (2): Linux utility with reverse index facility? "Chris F.A. Johnson" <cfajohnson@gmail.com> - 2011-05-16 15:59 -0400
      Re: Re (2): Linux utility with reverse index facility? Robert Klemme <shortcutter@googlemail.com> - 2011-05-17 02:14 -0500
  Re: Linux utility with reverse index facility? David Brown <david@westcontrol.removethisbit.com> - 2011-05-16 14:38 +0200
    Re: Linux utility with reverse index facility? Robert Klemme <shortcutter@googlemail.com> - 2011-05-16 08:10 -0500
  Re: Linux utility with reverse index facility? Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-05-16 15:08 +0200
  Re: Linux utility with reverse index facility? Stu <stu@rubyprogrammer.net> - 2011-05-16 12:52 -0500
  Re: Linux utility with reverse index facility? Robert Nichols <SEE_SIGNATURE@localhost.localdomain.invalid> - 2011-05-17 22:40 -0500
    Re: Linux utility with reverse index facility? Luuk <Luuk@invalid.lan> - 2011-05-18 19:14 +0200
    Re: Linux utility with reverse index facility? Ed Morton <mortonspam@gmail.com> - 2011-05-19 16:15 -0700
  Re: Linux utility with reverse index facility? Brian Candler <b.candler@pobox.com> - 2011-05-18 03:14 -0500

csiph-web