Bryan R Harris
Jul 11 2005, 09:35 PM
Is it possible to easily initialize an array so that:
$index[0] is a pointer to a new anonymous (?) array (0,0)
$index[1] is a pointer to a new anonymous (?) array (0,0)
...
$index[$#params] is a pointer to a new anonymous (?) array (0,0)
I tried:
@index = ([0,0]) x @params;
.... but it seems to create a bunch of pointers to the same array, e.g.
$index[1][0] points to the same thing as $index[0][0]. I need them to be
different.
TIA.
- Bryan
John W. Krahn
Jul 11 2005, 09:47 PM
Bryan R Harris wrote:
QUOTE |
Is it possible to easily initialize an array so that:
$index[0] is a pointer to a new anonymous (?) array (0,0) $index[1] is a pointer to a new anonymous (?) array (0,0) ... $index[$#params] is a pointer to a new anonymous (?) array (0,0)
I tried:
@index = ([0,0]) x @params;
... but it seems to create a bunch of pointers to the same array, e.g. $index[1][0] points to the same thing as $index[0][0]. I need them to be different.
|
@index = map [0,0], 0 .. $#params;
John
--
use Perl;
program
fulfillment
Bob Showalter
Jul 12 2005, 11:24 AM
Bryan R Harris wrote:
QUOTE |
Is it possible to easily initialize an array so that:
$index[0] is a pointer to a new anonymous (?) array (0,0) $index[1] is a pointer to a new anonymous (?) array (0,0) ... $index[$#params] is a pointer to a new anonymous (?) array (0,0)
I tried:
@index = ([0,0]) x @params;
... but it seems to create a bunch of pointers to the same array, e.g. $index[1][0] points to the same thing as $index[0][0]. I need them to be different.
|
push @index, [0, 0] for @params;
Bryan R Harris
Jul 12 2005, 04:54 PM
Excellent, thanks Bob and John!
- B
QUOTE |
Bryan R Harris wrote:
Is it possible to easily initialize an array so that:
$index[0] is a pointer to a new anonymous (?) array (0,0) $index[1] is a pointer to a new anonymous (?) array (0,0) ... $index[$#params] is a pointer to a new anonymous (?) array (0,0)
I tried:
@index = ([0,0]) x @params;
... but it seems to create a bunch of pointers to the same array, e.g. $index[1][0] points to the same thing as $index[0][0]. I need them to be different.
@index = map [0,0], 0 .. $#params;
John |
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.