Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #4725
| From | Brian Candler <b.candler@pobox.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Linux utility with reverse index facility? |
| Date | 2011-05-18 03:14 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <ada9767bab841a044c9285f78e4b7070@ruby-forum.com> (permalink) |
| References | <iqquq7$i46$1@dont-email.me> |
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 | Next — Previous in thread | Find similar | Unroll 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