Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8229017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:39:24+00:00 2026-06-07T16:39:24+00:00

I am writing a Perl script to automatically upload an Excel document into a

  • 0

I am writing a Perl script to automatically upload an Excel document into a MySQL database table using Automator in OSX. I have already written a functional query:

load data
local infile '/pathToFile/file.csv'
replace into table database.table
fields terminated by ','
enclosed by '"'
lines terminated by '\r'
ignore 1 lines;

The problem is my Perl script is not functioning because of a conflict with the \ character. I am kind of a Perl newbie, so I don’t know how to escape this character correctly to make the query work.

My Perl script:

#!/usr/bin/perl

# PERL MODULE
use Mysql;

# HTTP HEADER
print "Content-type: text/html \n\n";

# Set Variables
$host = "127.0.0.1";
$database = "database";
$tablename = "plugin_status";
$user = "user";
$pw = "password";

# PERL MySQL Connector
$connect = Mysql->connect($host, $database, $user, $pw);

# Run Query to update table
$myquery = "load data local infile '/pathToFile/file.csv' replace into table database.table fields terminated by ',' enclosed by '"' lines terminated by '\r' ignore 1 lines;";

# EXECUTE THE QUERY FUNCTION
$execute = $connect->query($myquery);

Here is the error generated:

String found where operator expected at perlfile.pl line 20, near ""load data local infile '/pathToFile/file.csv' replace into table database.table fields terminated by ',' enclosed by '"' lines terminated by '"
    (Missing operator before ' lines terminated by '?)
Backslash found where operator expected at perlfile.pl line 20, near "' lines terminated by '\"
    (Missing operator before \?)
syntax error at perlfile.pl line 20, near ""load data local infile '/pathToFile/file.csv' replace into table database.table fields terminated by ',' enclosed by '"' lines terminated by '"
Bad name after r' at perlfile.pl line 20.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:39:25+00:00Added an answer on June 7, 2026 at 4:39 pm

    if you want the resulting string to contain the two-byte-sequence \r you will need to escape the backslash when wrapping your string in-between ".

    Also remember that your string cannot contain any free " if you use " to wrap the contents of your string, if this is the case you will need to escape every " that you want to be a part of your string.. see the below example.

    my $data = "hello, I can write \"quotes\" inside my string";
    

    Though there are much simpler alternatives so that you don’t have to worry about escaping anything1.

    $myquery = q{
      load data local infile '/pathToFile/file.csv'
      replace into table database.table
      fields
        terminated by ','
        enclosed by '"'
        lines terminated by '\r'
      ignore 1 lines;
    };
    

    1. Unless you plan on using } in your string..


    Read more about strings and escape sequences here:

    • perlmonks.org – String Literals In Perl
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a perl script that will access a MySQL database to determine whether
I'm writing a script using Perl and Net::FTP, which is trying to upload a
I am writing a Perl/Tk script which displays Excel worksheets using the ss2tk example
I am writing a Perl script and using the Class::CSV module. I have an
I have a Perl script for writing data to a MySQL DB, runs fine.
I am writing a Perl script (in Windows) that is using File::Find to index
I am writing a script that executes a command remotely via SSH using perl.
Using perl 5.8.8 on windows server I am writing a perl cgi script using
I am writing Perl script. In that I have to read log4j.xml file from
I am writing a Perl script which needs to perform some validations. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.