Octavian Rasnita wrote:
Hi,

I have tried the following test program:

my @array = (
{a => 'aaa', b => 'bbb',},
{a => 'ala', b => 'bala',},
);

my @array2 = @array;

$array2[0]{a} = 'nanan';
push(@array2, 'test');

use Data::Dumper;
print Dumper [EMAIL PROTECTED];

The result was:

$VAR1 = [
          {
            'a' => 'nanan',
            'b' => 'bbb'
          },
          {
            'a' => 'ala',
            'b' => 'bala'
          }
        ];

I know why modifying an element from a hashref from the second array
modifies that element in the first array and why the new pushed element in
the second array is not shown in the first array, but I don't know how to
create a second array with all the elements of the first one, but totally
separately.

Is this possible somehow, or I will need to use foreach element of the first
array, and create the correspondent element in the second one?
The array doesn't have more levels, so I would like avoiding using a CPAN
module that can copy an entire data structure.

Thank you.

Teddy



You can use the typeglob to modify the symbol table so that the two arrays are synchronized but it does not work with 'my' variables:

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;

our @array = (
  {a => 'aaa', b => 'bbb',},
  {a => 'ala', b => 'bala',},
);

our @array2;
*array2 = [EMAIL PROTECTED];

$array2[0]{a} = 'nanan';
push(@array2, 'test');

print Dumper [EMAIL PROTECTED];
print Dumper [EMAIL PROTECTED];

__END__

BTW, use this one sparingly; it will confuse a lot of people.

--

Just my 0.00000002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to