update a column in input file by taking value from Database in perl.

Posted by Rahul Singh on Stack Overflow See other posts from Stack Overflow or by Rahul Singh
Published on 2011-01-07T15:49:05Z Indexed on 2011/01/07 15:53 UTC
Read the original article Hit count: 244

Filed under:

input file:

1,a,USA,, 2,b,UK,, 3,c,USA,,

i want to update the 4th column in the input file from taking values from one of the table.

my code looks like this:

my $customer_dbh = DBI->connect("DBI:Oracle:$INST", $USER, $PASS ) or die "Couldn't connect to datbase $INST"; my $cust_smh; print "connected \n "; open FILE , "+>>$input_file" or die "can't open the input file"; print "echo \n"; while(my $line=) { my @line_a=split(/\,/,$line); my $customer_id=$line_a[3]; print "$customer_id\n"; $cust_smh = $customer_dbh->prepare("SELECT phone_no from book where number = $line_a[0]"); $cust_smh->execute() or die "Couldn't execute stmt, error : $DBI::errstr"; my $number = $cust_smh->fetchrow_array(); $line_a[3]=$number; }

© Stack Overflow or respective owner

Related posts about perl