Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#! perl -w use strict; use Win32::ODBC; my $dir = 'K:\\reports'; my $count = 0; opendir DH, $dir or die "Cannot open $dir: $!"; while (my $file = readdir DH) { next unless $file =~ /\.pdf$/; my %newfile = substr($file,2,6); process_records($newfile); } closedir DH; sub process_records { my ($newfile) = @_; my $dbname = 'DB_Name'; my $username = 'Username'; my $password = 'Password'; my ($db); if (!ref($db = new Win32::ODBC("DSN=$dbname;UID=$username;PWD=$passwo +rd"))) { my ($ErrNum, $ErrText, $ErrConn) = Win32::ODBC::Error(); #...IT FAILED - DO SOMETHING... print "couldn't connect"; } my $sql = ("SELECT field1,field2,field3,field4,field5,field6,lastname, +firstname FROM db_name.table WHERE field1 = '029622'"); if($db->Sql($sql)){ #...FAILED... my ($ErrNum, $ErrText, $ErrConn) = $db->Error(); } my ( $yr, $mo, $dy ) = (localtime)[5,4,3]; my $outfile = sprintf( "C:\\Directory\\%04d%02d%02d.txt",$yr+1900,$mo+ +1,$dy ); open OUT,">$outfile" or die "Couldn't open $outfile, $!"; while($db->FetchRow()){ my %data = $db->DataHash(); #...Processing Data... print OUT "%data\n"; } $db->Close(); # }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting data using WIN32::ODBC
by Happy-the-monk (Canon) on Jun 14, 2004 at 22:20 UTC | |
|
Re: Extracting data using WIN32::ODBC
by jZed (Prior) on Jun 14, 2004 at 22:19 UTC | |
|
Re: Extracting data using WIN32::ODBC
by McMahon (Chaplain) on Jun 14, 2004 at 22:02 UTC | |
|
Re: Extracting data using WIN32::ODBC
by Wassercrats (Initiate) on Jun 15, 2004 at 03:53 UTC | |
|
Re: Extracting data using WIN32::ODBC
by periapt (Hermit) on Jun 15, 2004 at 12:42 UTC |