in reply to How can I open a filehandle so it is cleared and rewritten for every request?

Just use a new file handle (or re-open your existing one.) You'll also have to re-configure your curl object every time you do this, so you might want to make it into a subroutine:
use strict; use warnings; use WWW::Curl::Easy; my $curl = new WWW::Curl::Easy; $curl->setopt(CURLOPT_URL, 'http://cnn.com'); my ($r, $b, $h) = get_response($curl); print "retcode = $r\n"; print "body = $b\n"; sub get_response { my ($curl) = @_; my ($body, $head); open(my $body_fh, ">", \$body); open(my $head_fh, ">", \$head); $curl->setopt(CURLOPT_WRITEDATA, $body_fh); $curl->setopt(CURLOPT_HEADERDATA, $head_fh); my $retcode = $curl->perform; return ($retcode, $body, $head); }
  • Comment on Re: How can I open a filehandle so it is cleared and rewritten for every request?
  • Download Code

Replies are listed 'Best First'.
Re^2: How can I open a filehandle so it is cleared and rewritten for every request?
by skrapasor (Novice) on Jun 27, 2008 at 19:08 UTC
    Yeah, that makes sense, but I didn't think of it. BTW I really don't think my questions was unclear and you answered it perfectly.

      It was "unclear" to the extent that you didn't show the code. Perl monks are generally Perl programmers and Perl programmers are encouraged to be "lazy". One way that manifests itself is expecting the OP to provide all required information to frame their question in a clear an concise way. Following a link is often too much work and may be dangerous - it could lead to Wikipedia and waste hours of time for example.

      More seriously: including a link is frowned on because links can be transient. It is much better to provide your sample code in the node because all the context for the question has the same life time - the life time of the node.


      Perl is environmentally friendly - it saves trees