CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI:
Not all entries added

 



Fritter
New User

Nov 4, 2009, 11:42 AM

Post #1 of 1 (3098 views)
Not all entries added Can't Post

So I wrote a scipt to take a csv file and upload it to a database. It works fine except the csv files have some bad ascii characters in them (like ... as one character) so the ascii value is outside the standard set. Perl see's this as an escape or something and doesn't add the line. Is there an easy way to check to make sure all the values are within the normal ascii range so I don't get a lot of missing files because of special characters? Or can I handle them in a special way? Thanks! part of my code is below.




Code
   

#Set's the fields of the parsed file into a data array
@data=$csv->fields();

#Checks to make sure that all the lines aren't blank if not then continue.
if($#data == 20)
{
#Takes each field in the data array and sets it to the
#corosponding position in the database. If there is an error print
#out the message and quit
$sth->execute(@data->[0],@data->[1],@data->[2],@data->[3],@data->[4],@data->[5],@data->[6],@data->[7],@data->[8],

@data->[9],@data->[10],@data->[11],@data->[12],@data->[13],@data->[14],@data->[15],@data->[16])

or die "Couldn't execute: $DBI::errstr";
#increase the counter
$recnt++;
}
#If it fails print out the line that we couldn't parse
else
{
print "Unable to parse CSV line: ",$_, "\n";
}
}


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives