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?
When a string has double quotes within it, you need to escape them with
\.Also, Perl lets you use other characters for quote delimiters.
qqfollowed by almost any character is the same as double quotes. So you could do things like this to avoid the need of backslashes:And so on…
Update: How to execute a system command in Perl. There are three basic ways:
systemexecutes a command and waits for it to return. The return value is the exit status of the program.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.execis 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.