开发者

how to print out double quoted statement with variables in perl

开发者 https://www.devze.com 2023-02-05 21:59 出处:网络
I need some perl help trying to print this double quoted statement with variables, mixed with some unix sed commands that I can\'t seem to escape properly.

I need some perl help trying to print this double quoted statement with variables, mixed with some unix sed commands that I can't seem to escape properly.

I am not interested in executing it, but just want to print th开发者_StackOverflow社区is out to a file. Thanks for your help.

print  MYOUTFILE "mysql -u foo -pbar --database $dbsrc -h $node --port 3306 -ss -e \"SELECT 'a','b','c' UNION SELECT col1, col2, col3 FROM $tblist limit 10\" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > myDump.csv\"\n"`;

In particular this part is giving me a problem: | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > myDump.csv\"\n";


To reduce escape complications, use q and qq when needed:

print  MYOUTFILE qq{mysql -u foo -pbar --database $dbsrc -h $node --port 3306 -ss -e "SELECT 'a','b','c' UNION SELECT col1, col2, col3 FROM $tblist limit 10"}, q{ | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > myDump.csv}, "\n";


Use qq{string} instead of "string" to create an interpolated string that doesn't require double quote characters to be escaped. It makes things much easier to manage.

0

精彩评论

暂无评论...
验证码 换一张
取 消