note
muba
<p>hi [sankar R], welcome to Perlmonks! You might want to check the markup of your post, and throw in a few <code>...</code> tags to make it more readable.</p>
<p>As to answer your question:</p>
<p>1. If you want to access an element in a two-dimensional array, you'll need two indexes (one for each dimension). For an array to be two-dimensional, it just means that it is an array where each element is also an array (or more correctly, an array reference). If you just want to get the inner array without caring that it is an array, then you could do it with a single index.</p>
<p>2. I infer that you mean that you have an array with 10 elements, each containing an array of 2 elements. Is this correct?</p>
<p>3. Ok, that's clear. You want to access the elements of the inner arrays one by one.</p>
<p>4. Well...<br/>
a) What have you tried?<br/>
b) How did it work?<br/>
c) How didn't it work?<br/>
d) What output did you expect?<br/>
e) What output did you get, including error messages if any?</p>
<p>How does this fail you?</p>
<c>
use strict;
use warnings;
my @array1 = (
["first #1", "first #2"],
["second #1", "second #2"],
["third #1", "third #2"],
);
my $outer_idx = 0;
my $inner_idx = 0;
printf "One: %s; Two: %s\n", $array1[$outer_idx]->[0], $array1[$outer_idx]->[1];
$outer_idx++;
printf "One: %s; Two: %s\n", $array1[$outer_idx]->[0], $array1[$outer_idx]->[1];
</c>
<p>Output:</p>
<c>
One: first #1; Two: first #2
One: second #1; Two: second #2</c>
<p>5. I think I did that in point 4. :) Cheers.</p>
1038885
1038885