Я согласен с PacoRG, что вам, скорее всего, стоит подумать об использовании модуля из пространства LWP::
.Поскольку у вас есть более конкретные потребности, я бы порекомендовал LWP::UserAgent
.
При этом, если вам действительно нужно получить что-то, что печатается, вместо того, чтобы сохранить его в переменной, мы можем сыгратьнекоторые игры с более глубокой магией Perl.
# setopt method calls here
## the variable you want to store your data in
my $variable;
{
## open a "filehandle" to that variable
open my $output, '>', \$variable;
## then redirect STDOUT (where stuff goes when it is printed) to the filehandle $output
local *STDOUT = $output;
## when you do the perform action, the results should be stored in your variable
$curl->perform();
}
## since you redirected with a 'local' command, STDOUT is restored outside the block
## since $output was opened lexically (with my), its filehandle is closed when the block ends
# do stuff with $variable here
Возможно, у WWW::Curl::Easy
есть лучший способ сделать это, так как я не знаю команд этого модуля, я предоставил вам хак, который сделает то, что вам нужно.