My mind tumbled through several permutations in reading your post, so I hope one of them will prove helpful or illuminative.

When I first looked at this, the thought of "homework" passed briefly through my mind, but with just the ideas I am tossing out, it would still be up to you how best to implement the information, so I don't think that will be a factor herein.

My first thought about the question regarding how to put it into a data structure was that perhaps you were looking at something reminiscent of a radix sort. There are several references for such things online, easily found through a search such as Google, so I'll forego that as well.

One thing you may wish to look at is using a hash of arrays, so you might have something like $yourhash{'5'}(0..5) = ('567888871', '567888871', '567888871', '567888871', '546666624', '534889032'), for instance. You might wish to check my syntax, as I am writing this without a terminal window open to test it in, but you get the idea.

Another option might be an array of arrays, so that in the above you end up with $yourarray[5][4] = '546666624'.

You may wish to review perllol or another such reference for additional assistance.

I look forward to others' responses, so I may learn as well.


In reply to Re: How can I read multiple lines starting with the same number and put in to a nested array and print it to a file? by atcroft
in thread How can I read multiple lines starting with the same number and put in to a nested array and print it to a file? by opolat

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.