fiddle
fiddle

Reputation: 1162

Use of uninitialized value in concatenation (.) or string - error in perl script

I am trying to write the output of the below given perl to a CSV but it is giving this error. Can someone please help:

!/usr/bin/perl -w

BEGIN {   $ENV{ORACLE_HOME}='/u01/app/oracle/product/11.1.0/'; } 
use strict;

use DBI; 
use utf8;

my $DB='pre14msv'; 
my $db_user='SWAPP_OWNER'; 
my $password=`/usr/bin/pmo view password -u $db_user -t $DB`;
chomp($password); 
my $db = DBI->connect( "dbi:Oracle:pre14msv", $db_user, $password )
        || die( $DBI::errstr . "\n" );

$db->{AutoCommit}    = 0;
$db->{RaiseError}    = 1;
$db->{ora_check_sql} = 0;
$db->{RowCacheSize}  = 16;


my $sth = $db->prepare("SELECT 
        q.enq_time,DBMS_LOB.substr(q.user_data.chat_event_text,100) FROM
        swapp_owner.aq\$CHAT_EVENT_QUEUE_table q");

open my $fh, '>>', 'Output.csv' or die "Could not open file Output.csv: $!"; 
print $fh qq{q.enq_time\tq.user_data.chat_event_text\n};

$sth->execute; 
while (my $res = $sth->fetchrow_hashref) {   
    print $fh qq{$res->{'q.enq_time'}\t$res->{'q.user_data.chat_event_text'}\n}; 
}
close $fh;


print "If you see this, execute phase succeeded without a problem.\n";

END {
    $db->disconnect if defined($db); 
}

Upvotes: 0

Views: 2852

Answers (1)

Miller
Miller

Reputation: 35208

You're selecting two fields from your table, but neither of them is named Name or CompanyName.

Instead, why not try this:

while (my @res = $sth->fetchrow_array) {
    print $fh qq{$res[0]\t$res[1]\n};
}
close $fh;

Upvotes: 2

Related Questions