Joshua Scott wrote at Wed, 02 Jul 2003 21:25:34 -0400: > I'm trying to copy data from one database field to another. The problem is > that the field contains various newline and other types of control > characters. Whenever the script runs, it processes those as perl code > instead of data like I'd like it to. How can I prevent it from doing this? > > > Here is an example of what is happening. > > $variable = "Some data\nSome more data\n\nBlah Blah" > > This variable was populated from an SQL table. I'm trying to create a valid > SQL scripts file so I do the following. > > print FILE "INSERT into table (field) VALUES ('$variable');" > > The file gets created just fine, but when I view the file it looks like > this: > > ---- > INSERT into table (field) VALUES ('Some Data > Some more data > > Blah Blah
If the string ends with a ' it is a full valid SQL script. > Basically, I'd like it to look exactly as it is stored in the > variable...which would be like this: > > ---- > INSERT into table (field) VALUES ('Some data\nSome more data\n\nBlah > Blah"; > ---- > What do I need to do? You can do something like $variable =~ s/\n/\\n/gs; To say the truth, I would be more scared of e.g. ' contained in the string. Such stuff, I would prefer to quote with the DBI::quote method. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]