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

Yevgeny Simkin picture Yevgeny Simkin · Jun 19, 2009 · Viewed 23.8k times · Source

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?

Answer

sunny256 picture sunny256 · Jun 19, 2009

It probably sends its stuff to stderr. Try

my $foo = `curl yadd yadda 2>&1`;