# Parsing arrays and searching match on index

**URL:** <https://www.ruby-forum.com/t/parsing-arrays-and-searching-match-on-index/135733>\
**Category:** Ruby\
**Created:** [April 24, 2008, 3:13pm UTC](https://www.ruby-forum.com/t/parsing-arrays-and-searching-match-on-index/135733 "2008-04-24T15:13:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c6cbf5/32.png) [@shinji](https://www.ruby-forum.com/u/shinji)\
**Post date:** [April 24, 2008, 3:13pm UTC](https://www.ruby-forum.com/t/parsing-arrays-and-searching-match-on-index/135733/1 "2008-04-24T15:13:05Z")

</div>

I am finding that the following logic works, yet when applied in the  
attached file, it fails…

a = [[‘head1’,‘head2’,‘head3’],[‘a’,‘b’,‘c’],[‘x’,‘y’,‘z’]]  
puts a.class  
headings =a[0]  
puts headings.class  
b = a  
#puts a  
b.shift  
puts b.class

#puts headings  
mark1 = headings.index(“head2”)  
puts mark1  
mark2 = headings.index(“head3”)  
puts mark2  
puts “\n\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*”

b.each do |row|  
row.each do |elem|  
if row.index(elem) == mark1  
puts “Selected mark1: #{elem}”  
elsif row.index(elem) == mark2  
puts "Selected mark2: #{elem} "  
else  
puts “other”  
end  
end  
end
