Hello,
First post to this forum. I'm trying to retrieve data via DBI and
write it into a text file. Everything works fine with DBI but I don't
know how to write query results into my text file. My code is here:
##########################
#!/bin/perl
use warnings;
use strict;
use DBI;
my $dbs = "dbi:ODBC:DRIVER={servername};SERVER={serverip}";
my ($username, $password) = ('username', 'passwd');
my $dbh = DBI->connect($dbs, $username, $password)
or die "Can't connect to $dbs: $DBI::errstr";
my $sth = $dbh->prepare("select var1, var2 from mytable")
or die "Can't prepare statement: $DBI::errstr";
my $outfile = '>temp.txt';
open(OUTFILE, $outfile) or die "Unable to open $outfile: $!";
while (<OUTFILE>) {
chomp;
my ($var1, $var2) = split /,/;
$sth->execute($var1, $var2);
print $outfile;
}
close OUTFILE;
$sth->finish();
$dbh->disconnect();
############################
This produces the error message: Filehandle OUTFILE opened only for
output at myscript.pl line 28.
Many thanks,
-L
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/