ravi45722 has asked for the wisdom of the Perl Monks concerning the following question:
Here I am assigning(push) a hash to an array of hashes. But when I print hash Its perfect. But when I push that into an array its changing. Here is my code. I also tried with escape('\') character.
$string = "column08=Submit & column10=Delivered & column09=Something" my @matches = grep defined, split / ([|&]) /, $string; $i = 1; foreach my $one (@matches) { if (($one =~ tr/=//) == 1) { my ($key,$value)=(split /=/,$one); %hash = (); $hash{'term'}{$key} = $value; push (@return_array,%hash); } else { push (@symbol_array,$one); } } print Dumper \%hash; print Dumper \@return_array;
Expected Output:
Thanks in Advance$VAR1 = [ 'term'=> { 'column08' => 'Submit' }, 'term'=> { 'column10' => 'Delivered' }, 'term'=> { 'column09' => 'Something' } ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Assign a hash to an array
by choroba (Cardinal) on Jun 27, 2016 at 09:25 UTC | |
by ravi45722 (Pilgrim) on Jun 27, 2016 at 09:44 UTC | |
by GotToBTru (Prior) on Jun 27, 2016 at 12:58 UTC | |
by choroba (Cardinal) on Jun 27, 2016 at 11:31 UTC | |
|
Re: Assign a hash to an array
by hippo (Archbishop) on Jun 27, 2016 at 09:25 UTC | |
|
Re: Assign a hash to an array
by haukex (Archbishop) on Jun 27, 2016 at 09:42 UTC | |
|
Re: Assign a hash to an array (ref)
by Anonymous Monk on Jun 27, 2016 at 09:42 UTC | |
|
Re: Assign a hash to an array
by $h4X4_|=73}{ (Monk) on Jun 27, 2016 at 09:33 UTC |