Guru's, I need your opinion and help. I have this script that goes through a report to pull data. It works fine, but I need to add look up field from a SQL database. I am not sure if I should query just for that field when it hits the element I want to query the email address. Or, should I create a look up from a hash. Also, how would the hash be created from the SQL query. Let me know if you have any questions :)
#!/usr/bin/perl -w use strict; use warnings; use POSIX; use Win32::ODBC; my $procdate = POSIX::strftime('%m/%d/%Y %H:%M', localtime); my $filedate = POSIX::strftime('%Y-%m-%d', localtime); open PM, "C:/Ougoing/TESTFILE" or die "Couldn't open PIM Report file: +$!"; my ($company,$batch_num,$rundate,$effent_date,$entry_desc,$date_crt,$l +oad_num,$credits,$debits,$comp_ident,$ccd,$batches,$batch_cnt,$comp_e +mail); my %trans_details; my %details_for = (); $batch_num = 0; my $picture = + "./usb.jpg"; my $DSN = "DSN=TESTDB;UID=test;pwd=test;"; my $connection = new Win32::ODBC("$DSN"); if (!$connection){die "Could not open connection to DSN because of [$! +]";} my $SQL = "SELECT Client_ID, EMAIL_ADDRESS FROM Contact_Data WHERE Con +tact_Code = 1"; if ($connection->Sql($SQL)){ print "SQL failed: \n $SQL \n"; print "Error: " . $connection->Error() . "\n"; print $connection->Error() . "\n"; $connection->Close(); die;} $connection->FetchRow(); my %dbhash = $connection->DataHash(); while ($connection->FetchRow()){ my %dataRow = $connection->DataHash(); #PUT EACH ROW INTO AN HASH HERE?????????? }; while (my $pimrpt = <PM>) { next if ($pimrpt =~ m/^(\s)*$/ || $pimrpt =~ m/^(\*)/ || substr($p +imrpt,9,10) =~ m/SETTLEMENT/ || substr($pimrpt,12,6) =~ m/NUMBER/ || substr($pimrpt,8,9) =~ m/\d{9}/); next unless ( substr($pimrpt, 0, 8) =~ m/COMPANY/ || substr($pimrpt, 27, 1 +2) =~ m/BATCH NUMBER/ || substr($pimrpt, 51, 12) =~ m/DATE CREATED/ | +| substr($pimrpt, 79, 17) =~ m/ENTRY DESCRIPTION/ || substr($pim +rpt, 0, 7) eq $batch_num || substr($pimrpt, 0, 7) =~ m/^\s{6}\d/ #| +| ); if (substr($pimrpt, 0, 8) =~ m/COMPANY/) { $company = substr($pimrpt, 9, 18); $ccd = substr($pimrpt, 46,3); next; }; if (substr($pimrpt, 27, 12) =~ m/BATCH NUMBER/) { $batch_num = 0 + substr($pimrpt, 42, 7); $effent_date = substr($pimrpt, 69, 8); $comp_ident = substr($pimrpt, 102, 9); #ONCE I READ THIS VALUE OFF THE REPORT I WANT TO QUERY THE DATABASE. next; }; if (substr($pimrpt, 79, 17) =~ m/ENTRY DESCRIPTION/) { $entry_desc = substr($pimrpt, 101, 13); next; }; if (substr($pimrpt, 51, 12) =~ m/DATE CREATED/) { $date_crt = substr($pimrpt, 69, 8); $load_num = substr($pimrpt, 107, 4); next; }; if (substr($pimrpt,0,7) eq $batch_num || substr($pimrpt, 0, 7) =~ +m/^\s{6}\d/) { $debits = substr($pimrpt, 24,20); $credits = substr($pimrpt, 44,20); $batches += 1; s/^\s+//, s/\s+\z//, s/,// for $debits, $credits; }; my $trans_details = $details_for{$company}; unless ($trans_details){ $trans_details = []; # first time for this company. + $details_for{$company} = $trans_details; # create its array of + details. }; push @$trans_details, { company => $company, company_ident => $comp_ident, batch_number => $batch_num, effective_entry => $effent_date, entry_description => $entry_desc, date_created => $date_crt, load_number => $load_num, ccd => $ccd, debits => $debits, credits => $credits, batches => $batches, #THIS IS WHERE THE VARIABLE IS GETTING PUSHED INTO AN ARRAY TO GENERAT +E A FILE. email => $comp_email }; $batches = 0; };

In reply to SQL Lookup/HASH by drodinthe559

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.