4
490
I have a strange problem.
There is a template that I want to use for a few arrays.
But in one array I want to change one of the parameters in the
anonymous hash thats inside the array, but when I change the hash in
arrTwo then arrOne also changes.
Why is that!?
#Script begins
my @Template = (
{
name => "Person",
params => []
},
{
name => "Doggi",
params => []
}
);
@arrOne = @Template;
#Print array before changing the Other array
print $arrOne[1]->{name} . "\n";
my @arrTwo = @Template;
$arrTwo[1]->{params} = [['John','doe']];
$arrTwo[1]->{name} = "This does not work well!!!!";
#Print array after changing the Other array
print $arrOne[1]->{name} . "\n";
#Script ends
The script returns:
Doggi
This does not work well!!!!
instead of Doggi twice.
Thanks!
There is a template that I want to use for a few arrays.
But in one array I want to change one of the parameters in the
anonymous hash thats inside the array, but when I change the hash in
arrTwo then arrOne also changes.
Why is that!?
#Script begins
my @Template = (
{
name => "Person",
params => []
},
{
name => "Doggi",
params => []
}
);
@arrOne = @Template;
#Print array before changing the Other array
print $arrOne[1]->{name} . "\n";
my @arrTwo = @Template;
$arrTwo[1]->{params} = [['John','doe']];
$arrTwo[1]->{name} = "This does not work well!!!!";
#Print array after changing the Other array
print $arrOne[1]->{name} . "\n";
#Script ends
The script returns:
Doggi
This does not work well!!!!
instead of Doggi twice.
Thanks!