Hi mwill007,

Please use <code> tags so your code will display properly. See How do I post a question effectively?

In your problem description you say that when you print the string, you get the expected value, and it doesn't work - please tell us the exact error message. Second, you say that when you manually set the SQL to the same value, it works - this leads me to believe that the two strings are actually not the same. Please try using Data::Dumper to output them both, and use the option $Data::Dumper::Useqq=1; to make nonprintable characters easier to see. See the Basic debugging checklist.

Lastly, there are modules to help you to read CSV - Text::CSV - and modules that help building SQL, like SQL::Abstract:

use warnings; use strict; # example data my @dbcolumn = qw/ site_id site_store_type project site_city site_stat +e site_country project_begin /; my @splitarray = ('9999','SC OSR','Prebuild','Penfield','NY','US','8/8 +/2016 '); # make a hash out of two arrays of the same length my %data = map { $dbcolumn[$_] => $splitarray[$_] } 0..$#dbcolumn; # build the SQL statement use SQL::Abstract; my $sql = SQL::Abstract->new; my ($stmt, @bind) = $sql->insert('database.database', \%data); # debug: display the Perl variables holding the SQL use Data::Dumper; print Dumper($stmt, \@bind); __END__ $VAR1 = 'INSERT INTO database.database ( project, project_begin, site_ +city, site_country, site_id, site_state, site_store_type) VALUES ( ?, + ?, ?, ?, ?, ?, ? )'; $VAR2 = [ 'Prebuild', '8/8/2016 ', 'Penfield', 'US', '9999', 'NY', 'SC OSR' ];

Hope this helps,
-- Hauke D

Update: Added link to SQL::Abstract, thanks to Your Mother for the inspiration :-)


In reply to Re: building sql statement by haukex
in thread building sql statement by mwill007

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.