sai.dasika has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am a newbie to perl and curl. I tried to read the topics in faq but couldn't comprehend. I downloaded curl.zip and also installed strawberry perl.

Now i need to know how to use curl with perl. Please give me instructions to follow.

Please help me in this regard

Sai Dasika

Replies are listed 'Best First'.
Re: Curl and Perl
by davido (Cardinal) on Jun 23, 2010 at 07:10 UTC

    What are you trying to accomplish?

    It seems like you might be better off learning one tool at a time rather than trying to mix the two together without proficiency in either. Naturally I would favor learning Perl first, and then layering in other tools as you need them. After you've gotten comfortable enough with Perl you will be able to keep it straight while learning your way around another tool.

    But whatever your process for mastering these tools, the first question still stands: What are you trying to accomplish?


    Dave

Re: Curl and Perl
by Khen1950fx (Canon) on Jun 23, 2010 at 11:14 UTC
    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;

      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.

        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.
Re: Curl and Perl
by jettero (Monsignor) on Jun 23, 2010 at 11:07 UTC
    Normally you'd use curl to get Perl and then LWP installed and then use WWW::Mechanize to do whatever task you want to accomplish. If you really need to use curl for some reason, it might be just as easy to type the commands in your shell.
Re: Curl and Perl
by Sewi (Friar) on Jun 23, 2010 at 11:06 UTC
    Go to http://search.cpan.org and type in what you're looking for ("curl" in this case). Once you found a module suitable for your needs, start your cpan client and type "install MODULENAME" (replacing MODULENAME by what you found).
    The LWP module is more commonly used within Perl scripte, it might be worth a try unless you really need some curl functionality.