Hi Guys,

i am currently stuck with a script at the moment,

This script is going to pull information from a .csv and then perform a MySQL select on a database, i then need to print one field of the Query as the result.

I have changed the modulenames, database,tables and field names due to DPA reasons.

Please see below;

#!/usr/bin/perl use warnings; use Text::CSV; use DBI; use DBD::mysql; use modulename::DB; use modulelogname::Log; use Term::ReadKey; my $username = get_username(); my $password = get_password(); my $host = get_host(); my $db = new modulename::DB::Hosting "$0.ini"; $db->setDriver('mysql'); $db->setUsername($username); $db->setPassword($password); $db->setHostname($host); $db->setDatabase('database'); my $log = new modulelogname::Log; $log->init('loglog'); $log->log("== log =="); my $file = 'customers.csv'; my $csv = Text::CSV->new(); open (CSV, "<", $file) or die $!; while (<CSV>) { if ($csv->parse($_)) { my @columns = $csv->fields(); $custid = $columns[0]; foreach ($custid) { my $sql = "SELECT email FROM database.table WHERE field= +'$custid';"; $db->query($sql) or $log->log("Failed to update on que +ry $sql"); # $sth->execute() or die "Execute exception: $DBI::errs +tr"; while (@row = $db->fetch_assoc($row[0])) { print "$row[0]...\n"; $log->log("Email found for: $custid"); } } } else{ my $err = $csv->error_input; print "Failed to parse line: $err"; $log->log("Failed to parse line: $err"); } } close CSV; sub get_username { ReadMode 0; print "Enter Username:\n"; $username = <STDIN>; chomp($username); $username=~s/\s//g; return $username; } sub get_password { ReadMode 2; print "Enter Password:\n"; $password = <STDIN>; chomp($password); $password =~s/\s//g; return $password; } sub get_host { ReadMode 0; print "Enter host:\n"; $host = <STDIN>; chomp($host); return $host; }

This is the results i get;

[2014-02-14 14:30:51] Started at Fri Feb 14 14:30:51 2014 [2014-02-14 14:30:51] == customer email script == Hosting DB: [DBI connect dbi:mysql:database=DATABASE;hostname=hostname +, user ashley.jordan] Hosting DB: [connect ok from pid 2997] Hosting DB: SELECT email FROM database.table WHERE field='1598'; Can't call method "fetchrow_hashref" on an undefined value at /usr/share/perl5/modulename/DB.pm line 877, <CSV> line 1 (#1) (F) You used the syntax of a method call, but the slot filled by t +he object reference or package name contains an undefined value. Som +ething like this will reproduce the error: $BADREF = undef; process $BADREF 1,2,3; $BADREF->process(1,2,3); Uncaught exception from user code: Can't call method "fetchrow_hashref" on an undefined value at /usr +/share/perl5/modulename/DB.pm line 877, <CSV> line 1. at /usr/share/perl5/modulename/DB.pm line 877 modulename::DB::fetch_assoc('modulename::DB::Hosting=HASH(0x30cdb6 +8)', undef) called at ./scriptnamet.pl line 45

In reply to Issue with Print by Ashley Jordan

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.