unload the data into a text file with pipe delimitor using perl DBI informix similar to "unload" command in dbaccess


I just wanted to unload the data from informix database table into a text file with pipe delimiter. Which worked similar to dbacces "unload" command.
my $dbh1= DBI->connect("DBI:Informix:$dbname","","")
                or die " cannot connect to  Informix DB\n";

my $sth1 =$dbh1->prepare("select * from table");

Thanks in advance  
Who is Participating?
wilcoxonConnect With a Mentor Commented:
Add this to the code you already have above...
open OUT, '>outfile' or die "could not write file: $!";
while (my $row = $sth1->fetchrow_arrayref) {
    print OUT join('|', @$row), "\n";
close OUT;

Open in new window

sudarshan1985Author Commented:
The above code is working fine for me but near the outfile I am not able to get the output into a particular file

open OUT, '>outfile.txt' or die "could not write file: $!";  --> is working


my $exm = "/home/aaa/aa.txt";
open OUT, '>$exm' or die "could not write file: $!";  --> is not working

its getting the output into a file called $exm but I need the data to be copied to aa.txt

Thanks in advance

Single quotes prevent interpolation of variables.  Either of the below will work:

open OUT, ">$exm" or ... # use double-quotes to enable interpolation
open OUT, '>', $exm or ... # use the 3-argument form of open
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.