develooper Front page | perl.beginners | Postings from March 2010

':content_cb' give what to subroutine?

Thread Next
From:
raphael
Date:
March 12, 2010 04:09
Subject:
':content_cb' give what to subroutine?
Message ID:
a81c2f2d1003120408r35929687v829747d541ea437e@mail.gmail.com
Hi,

------ CODE ------

use strict;
use warnings;
use WWW::Mechanize;
use File::Basename;
use Number::Bytes::Human qw(format_bytes);

# CODE GOES ON HERE TILL

open( my $file2write, '>', "$base" );
binmode $file2write;

my $b;
$wmc->get(
"$link",
':content_cb' => sub {

my ($c, $r) = @_;        # what are $c and $r ????

$b += length($c);
if ($r->content_length) {
    printf STDERR "${base}${extension} -> %.2f%% : %s of %s          \r",
    100. * $b / $r->content_length,
    format_bytes($b),
    format_bytes($r->content_length);
}
print $file2write $c;
});

$b = 0;
print "\n";
close $file2write;

------ END ------

I got this snippet on perlmonks. It's a kind of progress bar. I want to know
what is being passed to @_ by ':content_cb' ??

my ($c, $r) = @_;

what are $c and $r?


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About