Here is my example demonstrating an advantage to merely operating through a reference.
I would find it to be much more tedious to do exactly the same thing on without a reference.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.