I want to query three different databases and put all the data into an array
(which works fine). Next I want to convert the timestamps in the array to
epochtime (Unix Time), then sort the array, and then convert back to
original time stamp. Can anyone help?
Here is my script:
###Use DBI to Make Connection
use DBI;
###Use ODBC module of DBI to connect to the DB
use DBD::ODBC;
###Variable to make connection to AMER DB Server
$p2pamer = DBI->connect( "DBI:ODBC:p2pamer", "user", "password" ) or
die( "Could not make connection to database: $DBI::errstr" );
###Variable to make connection to EMEA DB Server
$p2pemea = DBI->connect( "DBI:ODBC:p2pemea", "user", "password" ) or
die( "Could not make connection to database: $DBI::errstr" );
###Variable to make connection to AUST-ASIA DB Server
$p2paust = DBI->connect( "DBI:ODBC:p2paust", "user", "password" ) or
die( "Could not make connection to database: $DBI::errstr" );
###SQL Query
$query = " SELECT EnforcementDate, SourceIP, SourcePort, DestinationIP,
DestinationPort
FROM enforcement
WHERE EnforcementDate > CONVERT(DATETIME, '20050822', 112)
AND
EnforcementProtocolID = 10
ORDER BY EnforcementDate";
###Put all SQL Connection variables into an array, that way you can loop
through them...
@dbh = ($p2pamer, $p2pemea, $p2paust);
###Create a variable for the output file
$file = 'c:\perl\scripts\output.txt';
###Open the output file so it can be written too
open(OUTPUT, ">$file");
###Create the data array to hold the output
@data = <OUTPUT>;
###A loop to query each database and add the results to the @data array
foreach $dbh (@dbh)
{
$sth = $dbh -> prepare($query);
$sth -> execute;
while (@result = $sth->fetchrow_array())
{
push (@data, "@result \n");
print "@result \n";
}
}
print OUTPUT "@data \n";
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>