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.


True laziness is hard work

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.