Question

Why isn't this working?

eval "$response = $ua->request($r);"
print "$@";

gives:

syntax error at (eval 8) line 1, near "=" 
Was it helpful?

Solution

It isn't working because your double-quoted string is subject to interpolation, which is not going to go well, with those variables being expanded in place. And you need a semicolon outside your eval, not so much inside it. Try single quotes like so:

eval '$response = $ua->request($r)';

OTHER TIPS

A better question is why you are using a string eval, instead of a block eval?

eval { $response = $ua->request($r); }
print "$@";

An even better better question is why you are using eval in the first place? I suspect that you are using LWP::UserAgent and unless you implement your own request object, the 'request` method is unlikely do die.

Thus, why not simply use:

$response = $ua->request($r);

?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top