1

I have a script where I am trying to populate a perl hash I can dereference them fine when I do it individually

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";
     }

However when i just try and dereference the %spec_hash It only containst one $exch reference, while it should had two - the XISX and the XCBO. But it never gets to the XCBO.

#!/sbcimp/dyn/data/EVT/GSD/scripts/perl/bin/perl
use FOOConf; # this is our custom DBI module
use Data::Dumper ;
FOOConf::makeDBConnection(production);
my $dbh=$FOOConf::dbh;

my $query = "select e_risk_symbol from 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->prepare($query) or die "\n\nCould not prepare statement:".$dbh->errstr;
    $cur_msg->execute();
    while (my @row=$cur_msg->fetchrow_array) {
           $spec_hash{'XISX'}{$row[0]}=1;
           }
$query = "select e_risk_symbol from gsd_etds 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->prepare($query) or die "\n\nCould not prepare statement: ".$dbh->errstr;
     $cur_msg->execute();
     while (my @row=$cur_msg->fetchrow_array) {
          $spec_hash{'XCBO'}{$row[0]}=1;
          }

#while(my($key,$value) = each(%spec_hash)) {
#     print $key, "," .$value ;
#     print "\n";
#     }
#
#     foreach my $exch (sort keys %spec_hash) {
#         print "$exch: $spec_hash{$exch}" ;
#         }

 print Dumper(\%spec_hash);

this is the dumper - shouldn't the dumper contain the XCBO as well? Why does the hash only have the XISX elements?

$VAR1 = {
           'XISX' => {
                      'FCEL' => 1,
                      'GPS' => 1,
                      'MCO' => 1,
                      'DPZ' => 1,
                      'WM' => 1,
                      'SPLS' => 1,
                      'ILMN' => 1,
                      'BWLD' => 1,
                      'CTSH' => 1,
                      'EWU' => 1,
                      'MDVN' => 1,
                      'PDCO' => 1,
                      'AFAM' => 1,
                      'SHW' => 1,
                    }
        };
2
  • Are there any values in XCBO? Can you include a dump of $spec_hash for us to take a look at? Commented Aug 1, 2014 at 1:33
  • the CBOE pull down from the database is not working Commented Aug 1, 2014 at 1:44

1 Answer 1

1

Are you sure that you are populating it with those values?

Try adding a print statement in the while loop, something like this:

 while (my @row=$cur_msg->fetchrow_array) {
      $spec_hash{'XCBO'}{$row[0]}=1;
      print "DEBUG $row[0]\n";
 }

My guess is that your query is not returning any results to add to the hash. Unless I missed something, your other code looks fine.

Sign up to request clarification or add additional context in comments.

2 Comments

You are both correct - the database is connecting, but nothnig is getting pulled down. you would figure that it would throw some error
It won't produce an error, but there are ways within the ResultSet api to check if the results returned are empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.