in reply to Curl and Perl

Here's a sample script that downloads the CPAN README using ftp via curl:
#!/usr/bin/perl use strict; use warnings; use WWW::Curl; use WWW::Curl::Easy; { my $curl = WWW::Curl::Easy->new(); my $fh = 'README'; if( $curl ){ $curl->setopt(CURLOPT_HEADER,1); $curl->setopt(CURLOPT_URL, 'ftp://ftp.perl.org/pub/CPAN/README'); my $response_body; open(my $fh, '>', \$response_body); $curl->setopt(CURLOPT_WRITEDATA, $fh); $curl->setopt(CURLOPT_VERBOSE,1); my $retcode = $curl->perform(); if ($retcode != 0) { warn "An error happened: ", $curl->strerror($retcode), " ( +$retcode)\n"; warn "errbuf: ", $curl->errbuf; } $curl->curl_easy_cleanup; } else { warn " WWW::Curl::Easy->new() failed"; } } exit 0;

Replies are listed 'Best First'.
Re^2: Curl and Perl
by sai.dasika (Initiate) on Jun 23, 2010 at 13:19 UTC

    Hi

    I can create .pl perl script. I know the curl commands. But i want to use these both here. Since i have Curl as a extracted folder and perl installed,there should be a mechanism to write curl commands in perl(.pl file).

    I want help in using curl with perl. I hope i am clear this time

    So,the curl commands i have at hand should be used in the dot pl(.pl) file.So that i can execute the .pl file from command prompt.

    please help me with this issue

    Sai Dasika

      I'm still not really clear as to what you want to do. If you want to use libcurl from Perl, see WWW::Curl. If you want to run curl as an external process, read system.

        Hi

        Yes you are right..i want to use curl with perl. I have a extracted folder of curl with me and i installed strawberry perl on my system. Something like including the curl library(the curl folder i have) in perl,so that i can use the curl commands in the .pl file i create.

        Please help me to use the curl library in perl using some include or using type statements

      I think that this response was outdated, but if it could help other perl beginners, you can try :
      $resp = qx{curl -s http://any_url}
      It will work if you have curl installed, both in linux like windows.