机械化示例 - 安静简单但对我来说太复杂:需要解释
美好的一天,亲爱的社区。我是编程新手。我想更深入地研究 Perl。 所以我有一个机械化的例子 - 安静简单但对我来说太复杂:需要解释。我需要你的帮助!
use strict;
$|++;
use WWW::Mechanize;
use File::Basename;
my $m = WWW::Mechanize->new;
$m->get("http://www.despair.com/indem.html");
my @top_links = @{$m->links};
for my $top_link_num (0..$#top_links) {
next unless $top_links[$top_link_num][0] =~ /^http:/;
$m->follow_link( n=>$top_link_num ) or die "can't follow $top_link_num";
print $m->uri, "\n";
for my $image (grep m{^http://store4}, map $_->[0], @{$m->links}) {
my $local = basename $image;
print " $image...", $m->mirror($image, $local)->message, "\n"
}
$m->back or die "can't go back";
}
有人能给我逐行解释吗?
Good day dear community. I am new to programming. And i want to digg deeper into Perl.
So i have a Mechanize example - quiete simple but too complex for me: need explanations. I need your help here with this!
use strict;
$|++;
use WWW::Mechanize;
use File::Basename;
my $m = WWW::Mechanize->new;
$m->get("http://www.despair.com/indem.html");
my @top_links = @{$m->links};
for my $top_link_num (0..$#top_links) {
next unless $top_links[$top_link_num][0] =~ /^http:/;
$m->follow_link( n=>$top_link_num ) or die "can't follow $top_link_num";
print $m->uri, "\n";
for my $image (grep m{^http://store4}, map $_->[0], @{$m->links}) {
my $local = basename $image;
print " $image...", $m->mirror($image, $local)->message, "\n"
}
$m->back or die "can't go back";
}
can anybody give me a line by line explanation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试了第一条线路。
但是,您需要确保首先阅读并理解以下文档:
1) Perl简介 - 特别是变量作用域部分
2) Perl 数据
3) Perl 数据结构手册
PS 正如 Eric 在评论中所说,对于刚开始的人来说,这段代码绝对不是一个很好的例子。它有太多重要的想法/概念/移动部件。
I tried the first coupe of lines.
However you need to make sure to first read and understand the following documentation:
1) Perl Intro - especially variable scoping part
2) Perl data
3) Perl Data Structures Cookbook
P.S. As Eric said in the comment, this code is definitely NOT a very good example for someone just starting. It's got way too many non-trivial ideas/concepts/moving parts.