我需要能够计算我在下面的程序的输出,输出基本上应该看起来像
website-name.com - Breaking news, opinion, politics, entertainment, sports and culture.
Length 89008
Lines 1517
我试图创建它但是,它似乎正在工作,所以一点帮助将不胜感激
仅仅为了一些背景信息,我编写的程序正在使用LWP :: UserAgent;从网站获取内容并显示它,所以我想做的是计算输出并获得字符数量。
#!/usr/bin/perl
use strict;
use warnings;
require LWP::UserAgent;
my $size = length(content);
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get('http://kmra.org/');
if ($response->is_success) {
print $response-> title();
print "$size\n";
}
else {
die $response->status_line;
}
答案 0 :(得分:1)
您需要在获得响应后获取内容:
#!/usr/bin/perl
use strict;
use warnings;
require LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get('http://kmra.org/');
if ($response->is_success) {
my $size = length($response->content());
print $response->title();
print "$size\n";
} else {
die $response->status_line;
}