A nice way to do this is the way provided by the LWP::UserAgent module. It allows you to provide a code reference that gets invoked whenever it gets another chunk of a file. Check this:

my $sub = sub { my ($data, $res, $proto) = @_; # either write directly to file or push onto an array $filename ? print FILE $data : push(@res_lines, $data) +; # increment total length $data_recved += length $data; if ($already_drew_percentage) { # erase an old sign and draw a new one print "\b" x 9, sprintf('%03d%% done', (($data_recved / $res->content_length) * 100) +); } else { # draw the first percentage printf('%03d%% done', (($data_recved / $res->content_length) * 100) +); $already_drew_percentage = 1; } };

(Sorry about the tab mess...I'm not sure how to correct it.) Call it like this:

my $res = $agent->request($req, $sub, 1024)

Where $agent is an LWP::UserAgent, $req is an HTTP::Request and 1024 is the amount of bytes you want to get before invoking $sub.

That was ripped from the pronbot source. It allows you to either write binaries directly to file via the FILE handle and the value of $filename, or push the lines of the response onto an array which can later be joined. (You might have do declare some of the vars yourself :) I'd advocate using an LWP module for basic HTTP stuff, it's very easy, although this probably looks complex.



--
my one true love

In reply to Re: printing in a specific area of the console by Amoe
in thread printing in a specific area of the console by io

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.