Okay. So your problem is that you want to give individual names to the arrays contained within an Array of arrays. You know how to do this for a known number of arrays, but your data contains a variable number of them and you're unsure of the syntax required to do this dynamically.

The question you've got to ask yourself, is Why?

Reading your example code, it seems likely it's because you don't know how to refer to the elements of the nested arrays, and you think that by doing this is will be easier to refer to $riGeo5[3]?

If this is your reasoning, I think you will find that havng done this, it will make life harder rather than easier. For example, you show the code.

... print OUTPUT "Geo1: @riGeo1\n"; print OUTPUT "Geo2: @riGeo2\n"; print OUTPUT "Geo3: @riGeo3\n"; print OUTPUT "Geo4: @riGeo4\n"; print OUTPUT "Geo5: @riGeo5\n"; ....

Once you have achieved your renaming, printing out 5 arrays takes 5 print statements and if you had 1000 arrays you would need 1000 print statements!(*)

However, by sticking with the AoA's that you have, you can acheive the 5 lines above with one line:

print "Geo$_: @{$riPrimGroup[$_-1]}\n" for 1..5;
and with one small modification, that line will handle 1000 arrays or any number that you can fit in memory:

print "Geo$_: @{$rePrimGroup[$_-1]}\n" for 1..@riPrimGroup;

Now, getting back to the syntax of accessing the individual elements of the nested arrays. If you want access the 2nd element of the 4th array, the syntax is:

print $riPrimGroup[3][2];

I hope that will have convinced you that you don't need to rename the nested arrays with individually numbered names, and that you will take the time to read and understand perlman:perlreftut.

If however, you are not convinced and still want to do this, then the syntax you are searching for is referred to as "Symbolic References" and is described in a section of perlman:perlref with that name.

I would also strongly urge you to read and understand this before you read the section referenced above. If you still want to do it after that...I wish you the best of luck :)

However, be warned that, whilst symbolic references have their uses, they can lead to some very difficult to track down bugs. If you elect to use them without having a really good reason for doing so and you encounter problems, you are quite likely to not get a sympathetic hearing here at the Monastery.

(*) Not strictly true or perhaps that should be: Not no strict;ly true?


In reply to Re: Re: build geometry group by Anonymous Monk
in thread build geometry group by Frippe

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.