Thank you for your reply. Using the code below I get an error message: Global symbol "$var1" requires explicit package name at myscript.pl lin 29.
#!/bin/perl use warnings; use strict; use DBI; my $dbs = "dbi:ODBC:DRIVER={servername};SERVER={serverip}"; my ($username, $password) = ('username', 'passwd'); #Otetaan yhteys 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"; # ">" is not a part of the regular file name. my $outfile = "temp.txt"; # get the values of $var1 and $var2 firstly. # then execute the query below. $sth->execute($var1, $var2); # open a file for writting, see perldoc -f open open OUTFILE, ">", $outfile or die "..."; # read the records line by line,and write them to the file while(my @re = $sth->fetchrow_array) { print OUTFILE @re,"\n"; } close OUTFILE; $sth->finish(); $dbh->disconnect(); 2008/11/7 Jeff P. <[EMAIL PROTECTED]>: > > > > --- On Fri, 11/7/08, Lauri Nikkinen <[EMAIL PROTECTED]> wrote: > >> From: Lauri Nikkinen <[EMAIL PROTECTED]> >> Subject: Retrieve data via DBI and write into a file >> To: beginners@perl.org >> Date: Friday, November 7, 2008, 8:28 AM > >> >> my $outfile = '>temp.txt'; > > # ">" is not a part of the regular file name. > my $outfile = "temp.txt"; > > # get the values of $var1 and $var2 firstly. > # then execute the query below. > $sth->execute($var1, $var2); > > # open a file for writting, see perldoc -f open > open OUTFILE, ">", $outfile or die "..."; > > # read the records line by line,and write them to the file > while(my @re = $sth->fetchrow_array) { > print OUTFILE @re,"\n"; > } > > close OUTFILE; > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/