#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |