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.

As to answer your question:

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.

2. I infer that you mean that you have an array with 10 elements, each containing an array of 2 elements. Is this correct?

3. Ok, that's clear. You want to access the elements of the inner arrays one by one.

4. Well...
a) What have you tried?
b) How did it work?
c) How didn't it work?
d) What output did you expect?
e) What output did you get, including error messages if any?

How does this fail you?

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];

Output:

One: first #1; Two: first #2 One: second #1; Two: second #2

5. I think I did that in point 4. :) Cheers.


In reply to Re: how to use two dimensional array? by muba
in thread how to use two dimensional array? by sankar R

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.