my $dbh = DBI->connect(qq{DBI:CSV:csv_eol="\n";csv_sep_char=\\~}); $dbh->{'csv_tables'}->{'JPDObj'} = {'file' => 'data/objectives-cqdc.txt','col_names' => ["Obj","PosNbr","Year","Div","AVP","Dept","SDescr","Major","Methods","Results","Accompl","JanUp","LDescr","Changes","Chars","Goals","Budget","CFObj"]}; $dbh->{'RaiseError'} = 1; $@ = ''; my $query = "SELECT Obj,SDescr,Major,Year,LDescr FROM JPDObj WHERE PosNbr = '$Cposition' AND Year = '$Cyear'"; my $sth = $dbh->prepare($query); $sth->execute(); my $found_results = 0; my $count = 0; my $Obj; my $PosNbr; my $Year; my $Div; my $AVP; my $Dept; my $SDescr; my $Major; my $Methods; my $Results; my $Accompl; my $JanUpd; my $LDescr; my $CFObj; while (my $row = $sth->fetchrow_hashref) { $found_results = 1; $count=$count+1; #SETUP VARIABLES $Obj=$row->{'Obj'}; $Year = $row->{'Year'}; $SDescr = $row->{'SDescr'}; $Major = $row->{'Major'}; $LDescr = $row->{'LDescr'}; my $Nyear = $nextYear + 1; $CFObj=$row->{'CFObj'}; if ($found_results) { # some output code here } } #### 20140000020~00001576~2014~"testdata"~"testdata"~"testdata"~-~0~-~"Inserted on December 10, 2013"~-~-~-~-~20000000001~20130000001~1~-