M
moritz.maisel
Hi,
how (if at all) is the behaviour of delete() defined for "multi-level-
hash-references"?
What I expected from the code at the bootom was:
$VAR1 = {
'y' => {
'8' => {
'c' => 3,
}
},
'w' => {
'' => {},
'6' => {
'a' => 1,
}
},
'x' => {
'7' => {
'b' => 2,
}
},
'z' => {
'9' => {
'd' => 4,
}
}
};
But I got:
$VAR1 = {
'y' => {
'' => {},
'8' => {
'c' => 3,
'foo' => 'y'
}
},
'w' => {
'' => {},
'6' => {
'a' => 1,
'foo' => 'w'
}
},
'x' => {
'' => {},
'7' => {
'b' => 2,
'foo' => 'x'
}
},
'z' => {
'' => {},
'9' => {
'd' => 4,
'foo' => 'z'
}
}
};
It works as expected if I copy the reference to a helper variable and
doing the delete on that, but I would like to understand the behaviour
in the described case ...
Does anybody have an explanation? Or a hint where to find one on the
net?
Thanks in advance,
Moritz
-----
#!/usr/bin/perl
use Data:
umper;
$list = [
{ "foo" => "w", "bar" => "6" , "a" => 1 } ,
{ "foo" => "x", "bar" => "7" , "b" => 2 } ,
{ "foo" => "y", "bar" => "8" , "c" => 3 } ,
{ "foo" => "z", "bar" => "9" , "d" => 4 }
];
print Dumper $list;
foreach (@{$list}) {
$temp->{$_->{'foo'}}->{$_->{'bar'}} = $_;
delete($temp->{$_->{'foo'}}->{$_->{'bar'}}->{'bar'});
delete($temp->{$_->{'foo'}}->{$_->{'bar'}}->{'foo'});
}
print Dumper $temp;
how (if at all) is the behaviour of delete() defined for "multi-level-
hash-references"?
What I expected from the code at the bootom was:
$VAR1 = {
'y' => {
'8' => {
'c' => 3,
}
},
'w' => {
'' => {},
'6' => {
'a' => 1,
}
},
'x' => {
'7' => {
'b' => 2,
}
},
'z' => {
'9' => {
'd' => 4,
}
}
};
But I got:
$VAR1 = {
'y' => {
'' => {},
'8' => {
'c' => 3,
'foo' => 'y'
}
},
'w' => {
'' => {},
'6' => {
'a' => 1,
'foo' => 'w'
}
},
'x' => {
'' => {},
'7' => {
'b' => 2,
'foo' => 'x'
}
},
'z' => {
'' => {},
'9' => {
'd' => 4,
'foo' => 'z'
}
}
};
It works as expected if I copy the reference to a helper variable and
doing the delete on that, but I would like to understand the behaviour
in the described case ...
Does anybody have an explanation? Or a hint where to find one on the
net?
Thanks in advance,
Moritz
-----
#!/usr/bin/perl
use Data:
$list = [
{ "foo" => "w", "bar" => "6" , "a" => 1 } ,
{ "foo" => "x", "bar" => "7" , "b" => 2 } ,
{ "foo" => "y", "bar" => "8" , "c" => 3 } ,
{ "foo" => "z", "bar" => "9" , "d" => 4 }
];
print Dumper $list;
foreach (@{$list}) {
$temp->{$_->{'foo'}}->{$_->{'bar'}} = $_;
delete($temp->{$_->{'foo'}}->{$_->{'bar'}}->{'bar'});
delete($temp->{$_->{'foo'}}->{$_->{'bar'}}->{'foo'});
}
print Dumper $temp;