in reply to Re: Inputing info into Nested Arrays
in thread Inputing info into Nested Arrays

The whole:
@array = ( [ "foo", "bar"], [ "abc", "def"] );

thing seems to work just for small stuff, is there another way that will be a little easier for a large number of references?

Also, I don't see how the while ... bit will work.(please excuse me, I'm a newbie)

She-wolf
"Wha? I don't get it."

Replies are listed 'Best First'.
RE: RE: Re: Inputing info into Nested Arrays
by Cirollo (Friar) on Aug 21, 2000 at 20:52 UTC
    The while... bit splits each line up and puts the resulting array into an element of @array.

    split with no arguments takes a line from $_ and splits it on whitespace (e.g, /\s+/) after disregarding leading spaces. So, that creates the 'inner' array from each line (each word in the line is 1 element), and then the 'outer' array is created with each line as an element. So,

    This is a test. This is line #2
    would be read in like this:
    $array[0][0] = "This"; $array[0][1] = "is"; $array[0][2] = "a"; $array[0][3] = "test"; $array[1][0] = "This"; $array[1][1] = "is"; $array[1][2] = "line"; $array[1][3] = "#2";

    And of course, you are going to have to change this based on your data file's structure.

      So basically I'd have to have 11 columns and 100 rows?

      She-wolf
      "Wha? I don't get it."

        What we're all trying to say is:
        How would you prefer to write it? Perl can parse that.
        But without any concrete preferences other than "I want to end up with data structure X", all we can do is put little snippets out there.

        -- Randal L. Schwartz, Perl hacker