in reply to building sql statement

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 :-)

Replies are listed 'Best First'.
Re^2: building sql statement
by Your Mother (Archbishop) on Jul 25, 2016 at 19:19 UTC
Re^2: building sql statement
by mwill007 (Initiate) on Jul 25, 2016 at 19:37 UTC
    Thanks, I though there was some hidden characters. That option for data dumper is what I was needing the "\n\n". I will keep that in my do not forget pile. First program I have written with alot of string manipulation. I got tired of modifying my database update program, since the data never comes to me the same way. Now I add two lines two the excel file I receive, first line is which database,second line is the database fields with drop downs, the other lines is the data. This way I never have to manipulate the program again.