in reply to Re^2: undefined value as filehandle from Curl.pm
in thread undefined value as filehandle from Curl.pm

First, this *is* your code, and you're not checking whether the file opened successfully for read. Second, why are you breaking encapsulation by modifying the innards of the object?

Also, where are you getting the examples for calling setopt()? Everything I've found takes a reference, which you're not passing in.

Here's an example from Net::Curl::Easy:

$self->setopt( CURLOPT_FILE, \$self->{body} ); $self->setopt( CURLOPT_HEADERDATA, \$self->{head} );

I don't see any direct use examples for CURLOPT_READDATA.

I'm not in a position to test at the moment, so this is just a very wild guess, but first, ensure you handle opens correctly, then try the code as-is. If it still fails, try changing $lwpcurl->{agent}->setopt( CURLOPT_READDATA, $fh ); to $lwpcurl->{agent}->setopt( CURLOPT_FILE, $fh );. If that still doesn't work, try <c>$lwpcurl->{agent}->setopt( CURLOPT_FILE, \$fh );. All that said, I really, really don't think that modifying the agent like that was intended by the developers (I could be wrong though).

Can you please post a link to where you're taking your examples from, or what you're basing your code on?

Replies are listed 'Best First'.
Re^4: undefined value as filehandle from Curl.pm
by wanderedinn (Sexton) on Jun 28, 2016 at 16:14 UTC

    The open() I referenced is directly from LWP/Curl.pm, thus it is not my code.

    As for the setopt references, I'll be honest, I could not find any examples. I did attempt passing the filehandle reference, but resulted in the same error.

    As for the setip() examples, I got them from previous posts here in a different thread

        Yes, that is in my code. But, the error generated when running the script was not referencing my code:

        Can't use an undefined value as filehandle reference at /home/geof/httppost/lib/perl5/site_perl/5.8.8/LWP/Curl.pm line 236.

        my example code I posted should have had:

        open(my $fh, "<", "test.xml") or die "could not open input file ($!)\n";

        I had posted an older version of the code

Re^4: undefined value as filehandle from Curl.pm
by wanderedinn (Sexton) on Jun 28, 2016 at 19:17 UTC

    regardless of either:

    $lwpcurl->{agent}->setopt( CURLOPT_FILE, \$fh ); $lwpcurl->{agent}->setopt( CURLOPT_FILE, $fh );

    both generate the same previous error:

    Can't use an undefined value as filehandle reference at /home/geof/httppost/lib/perl5/site_perl/5.8.8/LWP/Curl.pm line 236.