Perl populating a hash from an array of hashes -


I have a script where I'm trying to populate a Pearl hash, when I personally do it I'll be able to dereference them properly

  while (my ($ key, $ value) = each (% {$ spec_hash {'XISX'}})} {print $ key, ",". $ Value; Print "\ n"; } While (my ($ key, $ value) = each (% {$ spec_hash {'XCBO}}} ")) {print $ key,", ". $ Value; Print "\ n"; }  

But when I try just% spec_hash and dereference, it only holds a $ exch reference, while it should have been two - XISX and XCBO but it never goes on XCBO .

  #! FOOConf using Sbcimp / dyn / data / EVT / GSD / script / Pearl / bin / pearl; # This is our custom DBI module usage data: dumper; FOOConf :: makeDBConnection (production); My $ dbh = $ FOOConf :: dbh; Choose e_risk_symbol from my $ query = "gsd_etds where level_name = 'EXCH_CS' and e_exch_dest = 'XISX' and e_symbol_comment in ('Bin_6', 'bin_56')"; If (! $ Dbh) {print "Error connecting to database; $ DBI :: errstr \ n"; } My $ cur_msg = $ dbh- & gt; Ready ($ query) or die "\ n \ nThe statement can not be prepared:". $ Dbh- & gt; Errstr; $ Cur_msg- & gt; Executed (); While (my @ line = $ cur_msg-> fetchrow_array) {$ spec_hash {'XISX'} {$ line [0]} = 1; } $ Query = "Select from gsd_etds e_risk_symbol where level_name = 'EXCH_CS' and e_exch_dest = 'XCBO' and e_combo_type = '9999'"; If (! $ Dbh) {print "Error connecting to database; $ DBI :: errstr \ n"; } $ Cur_msg = $ dbh- & gt; Ready ($ query) or die "\ n \ nThe statement can not be prepared:". $ Dbh- & gt; Errstr; $ Cur_msg- & gt; Executed (); While (my @ row = $ cur_msg- & gt; fetchrow_array) {$ spec_hash {'XCBO'} {$ line [0]} = 1; } #while (my ($ key, $ value) = each (% spec_hash)) {# print $ key, ",". $ Value; #print "\ n"; #} # # Foreign exchange my $ acquisition (sort keys% spec_hash) {# print "$ exch: $ spec_hash {$ exch}"; #} Print dumper (\% spec_hash);  

This is a dumper - should not even be XCBO in dump? Why are there only XISX elements in hash?

  $ VAR1 = {'XISX' = & gt; {'FCEL' = & gt; 1, 'GPS' = & gt; 1, 'MCO' = & gt; 1, 'DPZ' = & gt; 1, 'Wm' = & gt; 1, 'SPLS' => 1, 'ILMN' = & gt; 1, 'bwd' = & gt; 1, 'CTSH' = & gt; 1, 'EUUU = & gt; 1, 'MDVN' = & gt; 1, 'PDCO' = & gt; 1, 'AFAM' = & gt; 1, 'SHW' = & gt; 1,}};  

Are you really populating those values?

While adding a print statement to the loop, try something like:

  while (my @ line = $ cur_msg-> fetch_array) {$ spec_hash { XCBO '} {$ row [0]} = 1; Print "Delete Row [0] \ n"; }  

My guess is that your query is not returning to add any result to hash unless I miss something, your second code looks fine.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -