Help - Search - Member List - Calendar
Full Version: initialize array of pointers to (0,0) arrays
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Bryan R Harris
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
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
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
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



PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.