use Hash::Merge qw( merge ); sub getTop25{ my ($dbh, $sth); $dbh = DBI->connect('DBI:ODBC:cdratelistingservice','$db','$psswd' +); # ODBC connect unless ($dbh->ping) { print "Error opening database: $DBI::errstr\n"; exit; } my $connected = $dbh->ping; $dbh->{FetchHashKeyName}='NAME_lc'; @fields = ( "30_day", "60_day", "90_day", "180_day", "270_day", "1 +_year", "18_month", "2_year", "3_year", "4_year", "5_year", "v +ariable_1", "variable_2", "variable_3" ); my $num_fields; $num_fields = @fields; for (my $i=0;$i<$num_fields;$i++) { $sql = "Select TOP 25 $fields[$i], key from cdrates c, main m +WHERE r.key = m.key and m.valid = '$date' ORDER BY $fields[$i] DESC"; push @sql, $sql; } # @hashref demonstrates the advantage to merely # operating through a reference. $num_queries = @sql; for (my $j=0;$j<$num_queries;$j++) { # update to check whether or not the database queries are # successful or not my $hashref = $dbh->selectall_hashref($sql[$j], "key") or die +$dbh->errstr; push @hashref, $hashref; } # here i merge all hashes in order to display only # 1 instance of an institution that is posting a top25 # jumbo CD rate in any of the above catagories (fields) $num_hashref = @hashref; for (my $k=0;$k<$num_hashref;$k++) { %complex = %{ merge( \%complex, \%{$hashref[$k]} ) }; } my $num_merge=scalar(keys %complex); print "\n\t$num_merge RECORDS Found\n"; } sub GetStationNumbers{ my ($dbh, $sth); $dbh = DBI->connect('DBI:ODBC:poop'); # ODBC connect unless ($dbh->ping) { print "Error opening database: $DBI::errstr\n"; exit; } else { #print "\n\nQuerying ACT! dBASE DB\n\n"; } my $connected = $dbh->ping; $dbh->{FetchHashKeyName}='NAME_uc'; my $sql; my @sql, @hashref; foreach my $key (sort keys %complex) { $sql = "SELECT station_number FROM inst where key = '$key'"; push @sql, "$sql"; } my $num_qeries; $num_queries = @sql; for (my $j=0;$j<$num_queries;$j++) { # update to check whether or not the database queries are # successful or not my $hashref = $dbh->selectall_hashref($sql[$j], "key") or die +$dbh->errstr; push @hashref, $hashref; } my $num_hashref; $num_hashref = @hashref; for (my $k=0;$k<$num_hashref;$k++) { %complex = %{merge( \%complex, \%{$hashref[$k]} )}; # I use a reference here just because I felt like it. $HoH_ref = \%complex; } my $num_merge=scalar(keys %complex); }
In reply to Re: Re:^4 Double Hash Key
by 3dbc
in thread Double Hash Key
by whaled
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |