andrew peacock has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to use WWW::Curl for the first time, and I'm getting a "No URL Set" error even though the code looks OK. Here's the very basic code I've got this down to:
#!/usr/bin/perl
#
# Test script for Perl extension Curl::easy.
# Check out the file README for more info.
use CGI::Carp qw( fatalsToBrowser );
use WWW::Curl;
print "Content-type: text/html\n\n";
my $url = 'http://www.google.com';

print "Testing curl version ",WWW::Curl::Easy::version(),"\n";

my $curl= new WWW::Curl::Easy;
$curl->setopt(CURLOPT_URL, $url);
if ($curl->perform() != 0) {
    print "\n
Failed ::".$curl->errbuf."\n"; };
It generates the "No URL set" error. I've googled lots, and can't find anything substantial about this message. Can anyone help? Any advice would be greatly, greatly appreciated, Regards Andy
  • Comment on www::curl::easy = no url set error... Help please!

Replies are listed 'Best First'.
Re: www::curl::easy = no url set error... Help please!
by hipowls (Curate) on Feb 24, 2008 at 00:37 UTC

    The use statement should be

    use WWW:Curl::Easy;
    as it makes the constant CURLOPT_URL available.

    If you had use strict; in your program it would have pointed out the error

    Bareword "CURLOPT_URL" not allowed while "strict subs" in use at Perl- +2.pl line 13. Execution of Perl-2.pl aborted due to compilation errors.

Re: www::curl::easy = no url set error... Help please!
by Fletch (Bishop) on Feb 24, 2008 at 01:55 UTC

    And while not specifically an answer to your question, you may find LWP::Simple (and LWP::UserAgent upon which it sits, or possibly WWW::Mechanize if you need more browser-like behavior (cookies, sumitting forms)) a better supported option as they're the more "standard" web client modules (and you're more likely to find people familiar with them).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      thanks to both of you. The www::curl with or without ::easy was getting me confused, coupled with my host saying they could install www::curl only after I asked for www::curl::easy. And I'd totallt forgotten about LWP. It's been quite a while since I coded in Perl, as you can probably tell. Thanks alot guys. The ::Easy solved it, and the LWP might be a better way forward. I appreciate the response, Andy