http://www.perlmonks.org?node_id=782969

abhay180 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am trying to create an array of hashes in my code. The key value pairs are pretty repetetive...hence i thought i can generate them as a string and assign it the array. But this doesnt seem to work!
This is how the array should look like: $xentry[0] = {BUCK_0 => JUNK, BUCK_1 => JUNK, BUCK_2 => JUNK, BUCK_3 = +> JUNK} ; $xentry[1] = {BUCK_0 => JUNK, BUCK_1 => JUNK, BUCK_2 => JUNK, BUCK_3 = +> JUNK} ; So on....
############################################### For this i did the following:
$str=""; for(my $i=0; $j<100;$i+=1) { for(my $j=0; $j<4;$j+=1) { $str .= "BUCK"."_"."$j"." => "."JUNK".","; } #Removes the Comma at the end $str = substr($str,0,length($str)-1); #Appending flower braces. $str = "{".$str."}"; $xentry[$i] = $str; $str=""; }
Now if i try accessing "$xentry[0]->{BUCK_0}"...It doesnt seem to work. Can somebody let me know the right thing to do?