I am trying to create a multi-dimensional array

        $MyArray[ $SizeOfMyArray ];

So I can do this:

        print " $MyArray[ 0 ][ 0 ] \n";


And what I want to do is add items to the array dynamically






-----Original Message-----
From: Mark Anderson [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, January 15, 2003 1:47 PM
To: Liss, Mike; [EMAIL PROTECTED]
Subject: RE: Adding to multi-dimensional array dynamically via push...



> I would like to know if it is possible to do somthing like this: ( I 
> know I can't do it this way as Perl barfs when I tried it )
>
> $SizeOfMyArray = 2;
>
> $MyArray[ $SizeOfMyArray ];

Why are you trying to define the size of your array?

> push( @MyArray[ 0 ],  0 );         << --- complains here with < ERROR >
(see below )

What are you trying to do?  Assign '0' to the first position of the array,
or push 0 onto the array in the first position of the array?

The first would look like:
$MyArray[0]=0;
The second would look like:
push ($MyArray[0],0);

> push( @MyArray[ 1 ],  5 );
>
> foreach $item ( @MyArray )
> {
>     print " Number $item \n";
> }

                Hope this helps,
                                /\/\ark

Reply via email to