Hi!
Zwei Fragen zum Beispliel dieses Abschnittes:
$| = 1; # to flush next line
printf "%s =>\n\t", $url;
Macht es Sinn "$|" auf "1" zu setzten, wenn sich in der "printf"-Anweisung ein Newline-Zeichen befindet?
my $req = HTTP::Request->new(GET => $url);
$req->referer("http://wizard.yellowbrick.oz");
In der "HTTP::Request"-Doku habe ich die Methode referer nicht gefunden, dafür in "HTTP::Headers". Hat das etwas mit Vererbung zu tun?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl -w
# titlebytes - find the title and size of documents
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use URI::Heuristic;
my $raw_url = shift or die "usage: $0 url\n";
my $url = URI::Heuristic::uf_urlstr($raw_url);
$| = 1; # to flush next line
printf "%s =>\n\t", $url;
my $ua = LWP::UserAgent->new();
$ua->agent("Schmozilla/v9.14 Platinum"); # give it time, it'll get there
my $req = HTTP::Request->new(GET => $url);
$req->referer("http://wizard.yellowbrick.oz");
# perplex the log analysers
my $response = $ua->request($req);
if ($response->is_error()) {
printf " %s\n", $response->status_line;
} else {
my $count;
my $bytes;
my $content = $response->content();
$bytes = length $content;
$count = ($content =~ tr/\n/\n/);
printf "%s (%d lines, %d bytes)\n", $response->title(), $count, $bytes; }
(Perl Cookbook Example 20.1: titlebytes)