in reply to Push array to hash
Set $Data::Dumper::Deepcopy to true before dumping.
#!/usr/bin/env perl use Data::Dumper; use strict; use warnings; my %hash=("one two"=>"buckle my shoe","three four"=>"shut the door"); my @arrayOfHashes; for (1..3) { push @arrayOfHashes,\%hash; } warn 'BEFORE: ',Data::Dumper->Dump([\@arrayOfHashes],[qw(*arrayOfHashe +s)]),' '; $Data::Dumper::Deepcopy=1; warn 'AFTER: ',Data::Dumper->Dump([\@arrayOfHashes],[qw(*arrayOfHashes +)]),' ';
BEFORE: @arrayOfHashes = ( { 'one two' => 'buckle my shoe', 'three four' => 'shut the door' }, $arrayOfHashes[0], $arrayOfHashes[0] ); at DataDumperDeepCopy.t line 12. AFTER: @arrayOfHashes = ( { 'one two' => 'buckle my shoe', 'three four' => 'shut the door' }, { 'one two' => 'buckle my shoe', 'three four' => 'shut the door' }, { 'one two' => 'buckle my shoe', 'three four' => 'shut the door' } ); at DataDumperDeepCopy.t line 14.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Push array to hash
by haukex (Archbishop) on Jun 25, 2020 at 06:41 UTC | |
|
Re^2: Push array to hash
by Anonymous Monk on Jun 25, 2020 at 09:24 UTC |