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

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.

Replies are listed 'Best First'.
RE: RE: RE: Re: Inputing info into Nested Arrays
by She-wolf (Sexton) on Aug 21, 2000 at 20:56 UTC
    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

        Basically, I need to read in a text file and have each projects information put into an array. I later need to be able to easily call up a project with a certain ID number and have the information displayed in an html file and then also make it accesible to be updated.

        I'm hoping for an easier way then having to write something to compare an inputed project ID number to a row in the format previously shown.

        e.g. I don't want for project 35 to have to call up $array34,0, $array34,1, $array34,2, etc.

        This has to be easily usable for non tech people and take an unknown number of projects(up to 100)

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