Reputation: 377
I have the following URL to be executed with curl
my $workItemCommentorURL = "://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId="$id"&oslc_cm.properties=dc:title"
I get the error as:
Scalar found where operator expected at ./clone.pl line 90, near ""://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId="$id"
(Missing operator before $id?)
String found where operator expected at ./clone.pl line 90, near "$id"&oslc_cm.properties=dc:title""
Tried to escape double quotes with following options:
"://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId=\"&id\"&oslc_cm.properties=dc:title"
"https://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:\"userId=" .$id. "\"&oslc_cm.properties=dc:title"
With this able to get the result but still getting the warning message as:
sh: oslc_cm.properties=dc:title: command not found
How should I escape the quotes in URL to get the result without warning sh: oslc_cm.properties=dc:title: command not found
My code is:
my $workItemCommentorURL = "https://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId=\"$id\"&oslc_cm.
my $result = qx(curl -s -D - -k -b ~/.jazzcookies -o commentor.json -H \"Accept: application/x-oslc-cm-changerequest+json\" $workItemCommentorURL);
Upvotes: 2
Views: 1451
Reputation: 9101
The message you get from sh
is caused by the &
in the url. The url needs to be escaped/quoted for the shell. Otherwise the shell interprets the &
as a special character.
Try this (notice the single quotes):
my $result = qx(curl -s -D - -k -b ~/.jazzcookies -o commentor.json -H 'Accept: application/x-oslc-cm-changerequest+json' '$workItemCommentorURL');
Upvotes: 4
Reputation: 35198
If you don't want to interpolate variables. Use single quotes:
my $workItemCommentorURL = '://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId="$id"&oslc_cm.properties=dc:title';
If you do want interpolation, then use the alternative form qq{}
:
my $workItemCommentorURL = qq{://xyz.com/jazz/oslc/users.json?oslc_cm.query=rtc_cm:userId="$id"&oslc_cm.properties=dc:title};
Upvotes: 2