I am using DBD::CSV and fetchrow_hashref and not getting results. In my example below, the variables $Cposition and $Cyear have already had values assigned.

Here is my database handler:

my $dbh = DBI->connect(qq{DBI:CSV:csv_eol="\n";csv_sep_char=\\~}); $dbh->{'csv_tables'}->{'JPDObj'} = {'file' => 'data/objectives-cqdc.tx +t','col_names' => ["Obj","PosNbr","Year","Div","AVP","Dept","SDescr", +"Major","Methods","Results","Accompl","JanUp","LDescr","Changes","Cha +rs","Goals","Budget","CFObj"]}; $dbh->{'RaiseError'} = 1; $@ = ''; my $query = "SELECT Obj,SDescr,Major,Year,LDescr FROM JPDObj WHERE Pos +Nbr = '$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 } }

It yields no results despite this record being in the file:

20140000020~00001576~2014~"testdata"~"testdata"~"testdata"~-~0~-~"Inse +rted on December 10, 2013"~-~-~-~-~20000000001~20130000001~1~-

And it should find results based on the second and third fields. Permissions on all files are correct and nothing comes across in my error log.

-Jacvivs


In reply to DBD::CSV and fetchrow_hashref not working by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.