Here's my code which still isn't working quite right. Please forgive my non use of strict... I'll clean that up when the functionality works. Partlist contains:
MIXORD077768 MIXORD077769
#!/bin/perl #use strict; #allows use of the copy and move commands for files use File::Copy; #allows for parsing words use Text::ParseWords; use Win32::ODBC; use Time::Local; use POSIX; use Data::Dumper; #for emailing errors use Net::SMTP; # oracle uid and pw my $user= 'test'; my $passwd = 'test'; #######Prod Variables my $outbox = "D:\\scripts\\outbox\\"; my $archive = "D:\\scripts\\archive\\"; my $log = "D:\\scripts\\log\\log.txt"; my $partlist = "D:\\scripts\\partlist.txt"; #put view for in an array to loop through each db @datasources = ("my_datasource"); foreach $datasource (@datasources) { #open logfile open(LOG_FILE, ">>$log")||die "Can't open file: $!"; print LOG_FILE ("begin\n"); #initiate DB ($Db) = new Win32::ODBC("DSN=$datasource;UID=$user;PWD=$passwd"); if (!$Db){ print LOG_FILE ("Could not open connection to DSN because of [$!]\n"); die "Could not open connection to DSN because of [$!]"; print LOG_FILE ($Db->Error()."\n"); print ($Db->Error()."\n"); } ## populate the string that will be used for the SQL query my $statement; $statement = "SELECT DISTINCT a.ordnum ORDNUM, a.shipid SHIPID, a.date + DATE"; $statement = $statement." FROM new_view a"; $statement = $statement." order by ORDNUM"; $Db->Sql($statement); ##Step through each returned row while ($Db ->FetchRow()) { my (%dataRow) = $Db->DataHash(); my $ordnum = $dataRow{'ORDNUM'}; my $shipid = $dataRow{'SHIPID'}; my $date = $dataRow{'DATE'}; #set custmoer variable for if ($shipid eq '12345678') { $customer='CUSTOMER1'; } else { $customer='OTHERS'; } #put date in zulu format my $date_z = substr($dataRow{'DATE'},0,10)."T".substr($dataRow{'DA +TE'},-8).".000-0000"; #get the parts that have already been printed open(PARTS, $partlist) || die "Can't open file: $!"; chomp(@PARTS = <PARTS>); %hash_table = (@PARTS); close PARTS; if ( defined( $hash_table{ $ordnum } ) ) { #?? } else { my $verifile = $outbox.$ordnum.".dat"; ##Open output file to write to open(OUTPUT_FILE, ">>$verifile")||die "Can't open file: $!"; print OUTPUT_FILE ".$ordnum.",".",".$shipid.","."".$customer.",".d +ate_z."\n"; close OUTPUT_FILE; } #end if part defined #add the part to the text file so we don't print it in the future my $partfile = $partlist; open(OUTPUT_FILE, ">>$partfile")||die "Can't open file: $!"; print OUTPUT_FILE $ordnum."\n"; close OUTPUT_FILE; close LOG_FILE; }# end of while FetchRow $Db->Close(); }#end for each datasource

In reply to Re^7: Looping through a file by baixiaohu
in thread Looping through a file by baixiaohu

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.