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 8736155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:14:26+00:00 2026-06-13T10:14:26+00:00

This is my perl script code. in this i’m getting error like bareword found

  • 0

This is my perl script code. in this i’m getting error like “bareword found where operator expected at $cmd”

my $path = $folder."/".$host."_".$database_name.".bak";
$cmd .= "-U $user_name -P $password -S $host -d master -Q "BACKUP DATABASE [$database_name] TO DISK = N'$path'" ";

any one help me?

  • 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-13T10:14:28+00:00Added an answer on June 13, 2026 at 10:14 am

    When a string has double quotes within it, you need to escape them with \.

    $cmd .= "-U $user_name -P $password -S $host -d master -Q \"BACKUP DATABASE [$database_name] TO DISK = N'$path'\" ";
    

    Also, Perl lets you use other characters for quote delimiters. qq followed by almost any character is the same as double quotes. So you could do things like this to avoid the need of backslashes:

    $cmd .= qq(-U $user_name -P $password -S $host -d master -Q "BACKUP DATABASE [$database_name] TO DISK = N'$path'" );
    
    $cmd .= qq|-U $user_name -P $password -S $host -d master -Q "BACKUP DATABASE [$database_name] TO DISK = N'$path'" |;
    

    And so on…

    Update: How to execute a system command in Perl. There are three basic ways:

    system($cmd);  #Goes through the shell if shell metacharacters are detected.
    system(@command_and_args);  #first element is the command, the rest are arguments
    

    system executes a command and waits for it to return. The return value is the exit status of the program.

    my @results = `$cmd`;  #Always goes through shell.
    

    Backticks execute a command and return its output. You should only use this if you actually need the output; otherwise, it is better to go with system.

    exec $cmd;
    exec @command_and_args;
    

    exec is exactly like system, except that it never returns. It effectively ends your program by calling another program.

    Use the one that is most appropriate to your situation. Or in this case, since you are executing SQL, consider using the DBI module. It’s definitely a better approach for anything more than a couple of simple commands.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple perl script but i am getting this runtime error: Can't
I want my perl script to be able to do this: $ ./code file.txt
I have this Perl script sitting in the cgi-bin folder of my Apache server:
I have a perl script that's reading an INI file like this: [placeholder_title] Hostname
Perl newbie here...I had help with this working perl script with some HASH code
I found this Perl script while migrating my SQLite database to mysql I was
Has anyone run perl script given at http://oreilly.com/pub/h/974#code ? This is a famous one,
Is it possible to return an error code from a perl script? I am
I have a Perl script that contains this code snippet, which calls the system
what is the correct way to code this perl statment in tcsh shell script

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.