Click to See Complete Forum and Search --> : perl script, need to create unknown number of arrays


DrJones
04-19-2003, 10:41 PM
I'm writing a perl script that reads in some info from a file and stores the info into an array. The problem is I have several files (all are the same format), and I don't know how many (it's a command line arg). I can't for the life of me figure out how to do it. If i knew there would be 10 or whatever i could just hard code it. In C++ I would just use a 2 dimensional array being array[filenumber][itemnumber], but in perl i can't figure it out or find anything online. If you do

$array1[0]=@array2

it seems to just expand array 2 and store them into 1, not quite what i'm looking for. Is there any way maybe to create the variable names on the fly? ie do something like array$j[0]=data[i]? I'm sure there is some easy solution to this (perl seems to be full of easy (but hard to find) solutions).

Thanks,
Dr. Jones

madcompnerd
04-20-2003, 04:40 PM
I'm no expert PERL programmer, but as far as I can tell from my reference book on it PERL treats two dimensional arrays very easily. It seems to dimension them automatically for you.
So first use
ex:
$matrix[0][0] = "data";

joesbox
04-20-2003, 06:08 PM
have you thought about the <readdir> function?? you will be able to put all of the names of the files into an array and then do a <foreach> to work with each file.