As Corion has suggested, a very effective tool for finding where a problem lies is to reduce the code to just enough to see the issue. You may find some of the techniques described in I know what I mean. Why don't you? helpful for focussing on just the code you need to demonstrate the problem. In the case of your problem you might reduce the code to:
use strict; use warnings; use Data::Dumper qw(); use Data::Dump::Streamer qw(); my %switch_param; my $switch_optional; $switch_optional->{foo} = 'bar'; my @optional; for (1 .. 3) { @optional = (@optional, $switch_optional); } $switch_param{"optional"} = [@optional]; Data::Dump::Streamer::Dump \%switch_param; print "\n\n"; print Data::Dumper::Dumper (\%switch_param);
which prints:
$HASH1 = { optional => [ { foo => 'bar' }, 'V: $HASH1->{optional}[0]', 'V: $HASH1->{optional}[0]' ] }; $HASH1->{optional}[1] = $HASH1->{optional}[0]; $HASH1->{optional}[2] = $HASH1->{optional}[0]; $VAR1 = { 'optional' => [ { 'foo' => 'bar' }, $VAR1->{'optional'}[0], $VAR1->{'optional'}[0] ] };
That might, or might not, make it clear to you where the issue is, but it does make it much clearer to us not only where, but what the problem is. Note that the code uses two different data structure dumping routines which show the output somewhat differently. You may find the Streamer version more clearly illustrates the issue.
Update added Streamer dump.
In reply to Re^3: Hash ref assignment to array results in anomaly
by GrandFather
in thread Hash ref assignment to array results in anomaly
by perlpal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |