perlcurlbackticksqx

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?


Solution

  • It probably sends its stuff to stderr. Try

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