Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the output of curl into a variable in Perl if I invoke it using backtics?

I'm trying to get the response of a curl call into a variable in perl.

my $foo = `curl yadd yadda`;

print $foo;

does not work. When I run this at the command line the curl call prints all its output correctly in the terminal, but the variable is not filled with that data.

Is there a way to do this without installing and calling the Perl curl lib?

like image 745
Yevgeny Simkin Avatar asked Jun 18 '09 22:06

Yevgeny Simkin


1 Answers

Very old post, but the real way of using curl in backticks is using the appropriate switch of curl.

This switch is -o which defines where to send the output.

More from the curl man page:

Specifying the output as '-' (a single dash) will force the output to be done to stdout.

This also prevents having possible errors in $foo, which would happen if you redirect the complete STDERR to STDOUT on errors:

my $foo = `curl -o - yadd yadda`;
like image 74
Jimmy Koerting Avatar answered Oct 20 '22 00:10

Jimmy Koerting