curl-library
Re: setopt(CURLOPT_*,$curlopthash->{$option}) apparently doesn't work
Date: Thu, 09 Oct 2008 10:20:10 +0100
Wurtz, Frederick (GE, Research, consultant) wrote:
>
> %curlopthash = (
> CURLOPT_URL => $url,
> CURLOPT_PROXY => "",
>
...
>
> foreach my $option (keys(%$curlopthash)) {
> $curl->setopt($option,$curlopthash->{$option});
> }
>
I'm familiar with curl and perl (though not the two together before) and
I think I see the problem
>
> I've verified that $option is, in each case the correct "CURLOPT_*"
> string and that $curlopthash->{$option} contains the correct values
>
It is not a string you want here, but the integer equivalent of the
option. CURLOPT_URL etc. are defined as constants, equivalent to
sub CURLOPT_URL {10000+2}
$ perl -e 'use WWW::Curl::Easy; print CURLOPT_URL'
10002
Perl treats the bare token before '=>' as a string. Compare:
$ perl -e 'use WWW::Curl::Easy; %x=(CURLOPT_URL=>'foo'); print join("
",%x);'
CURLOPT_URL foo
$ perl -e 'use WWW::Curl::Easy; %x=(CURLOPT_URL,'foo'); print join(" ",%x);'
10002 foo
Similar magic happens between curlies:
gen-off-27:~/Incoming/WWW-Curl-3.12
$ perl -e 'use WWW::Curl::Easy; $x{CURLOPT_URL}='foo'; print join(" ",%x);'
CURLOPT_URL foo
$ perl -e 'use WWW::Curl::Easy; $x{(CURLOPT_URL)}='foo'; print join("
",%x);'
10002 foo
Hope this helps
-- Colin HogbenReceived on 2008-10-09