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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.