Hello monks!
I have a file with many lines, and I want to pass the contents of each line to a different array, so for example @array1 will hold the data from line 1. @array2 will hold the data from line 2, etc...
The thing is, while I open the file and read it line by line, how can I create the different array dynamically? If I knew that I had X lines, I could create X arrays beforehand. But is there a way to use a counter and increment it each time you read a line and then use the number 1,2,3...of the counter to create the arrays?
$counter=0; open IN, $myfile; while(<IN>) { $line=$_; chomp $line; $counter++; $name_of_array="array_$counter"; } close IN;
apparently the line that I try to include the value of the counter in the array's name is not what I need. Can you help me?

In reply to Create dynamically different array names based on counter incrementation by Anonymous Monk

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.