in reply to Re: Unwanted cloning of array elements
in thread Unwanted cloning of array elements
Hippo! Thank you so much for that link on deep-copy mechanics. That's exactly what I needed :)
Fixed code
#!/usr/bin/perl use strict; my $Action; my $piece; $piece->{this} = 123; $piece->{that} = 'some text'; foreach my $other (111...113){ my $thispiece = {%$piece}; # create a deep copy $thispiece->{theother} = $other; push(@{$Action}, $thispiece); } use Data::Dumper; print Dumper($Action);
And now the output looks like I expected it to:
$VAR1 = [ { 'that' => 'some text', 'theother' => 111, 'this' => 123 }, { 'theother' => 112, 'that' => 'some text', 'this' => 123 }, { 'this' => 123, 'theother' => 113, 'that' => 'some text' } ];
Hippo FTW!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Unwanted cloning of array elements
by AnomalousMonk (Archbishop) on May 07, 2021 at 11:19 UTC |