
kuroneko1313
New User
Jul 31, 2012, 7:43 AM
Post #1 of 2
(598 views)
|
|
Clearing Up Single Quotation Mark
|
Can't Post
|
|
Hello, I have a Perl script that reads and parses from a text file and then do some SQL database updates and inserts. My problem is there are some single quotation mark in the input text file that keeps messing up with the SQL Query. I'm trying to use the Search and Replace function like $last_name =~ s/'/ /gi; but it never works out for me... This is how my code looks like: PARSING AND READING RESIDENT NAME FROM THE TEXT FILE: $field_7 =~ s/^\s+//g; # Resident Name $field_7 =~ s/\s+$//g; $resident_name = $field_7; $last_name = $resident_name; $last_name =~ s/'/ /gi; # SEARCH AND REPLACE A SINGLE QUOTATION WITH A SPACE if ( index($resident_name," ") > 0 ) { $first_name = substr($resident_name,0,index($resident_name," ")); $last_name = substr($resident_name,index($resident_name," ") + 1); $last_name =~ s/'/ /gi; # SEARCH AND REPLACE A SINGLE QUOTATION WITH A SPACE } THEN INSERT RESIDENT NAME INTO SQL DATABASE: insert into IntegrationResident values ( '$first_name' ,'$last_name') -- FAILED HERE BECAUSE OF A SINGLE QUOTATION MARK I think this is because I'm not doing my Search and Replace correctly... Could anyone please help me on this one? Thanks!
|