Reputation: 3909
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 this 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";
Upvotes: 0
Views: 3028
Reputation: 74252
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";
Upvotes: 4
Reputation: 943686
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.
Upvotes: 2