0

粉丝

很抱歉这个新手问题,但我在谷歌上找不到我需要知道的东西。我理解 print ,但不明白这个......

http://www.unifr.ch/sfm
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 2.
http://www.zug.phz.ch

在下面看到更多......

嗯 - 这是什么意思?

非常感谢您的耐心。

从头开始:好吧,我运行这个脚本,它是为了做一些网站的截图而写的真正的清单 - 真正的清单要长得多。它包含超过 3500 行和 URL

http://www.unifr.ch/sfm
http://www.zug.phz.ch
http://www.schwyz.phz.ch
http://www.luzern.phz.ch
http://www.schwyz.phz.ch
http://www.phvs.ch
http://www.phtg.ch
http://www.phsg.ch
http://www.phsh.ch
http://www.phr.ch
http://www.hepfr.ch/
http://www.phbern.ch
http://www.ph-solothurn.ch
http://www.pfh-gr.ch
http://www.ma-shp.luzern.phz.ch
http://www.heilpaedagogik.phbern.ch/

奇怪的是输出 - 见下文......问题:我应该更改脚本吗

为什么我要使用以下小脚本获取输出:

!/usr/bin/perl

use strict;
use warnings;
use WWW::Mechanize::Firefox;

my $mech = new WWW::Mechanize::Firefox();

open(INPUT, "<urls.txt") or die $!;

while (<INPUT>) {
        chomp;
        print "$_\n";
        $mech->get($_);
        my $png = $mech->content_as_png();
        my $name = "$_";
        $name =~s/^www\.//;
        $name .= ".png";
        open(OUTPUT, ">$name");
        print OUTPUT $png;
        sleep (5);
}

在这里看到压倒性的输出 - 坦率地说,我从来没有想过得到如此有趣的输出..我必须调试整个代码....见下文,

http://www.unifr.ch/sfm
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 2.
http://www.zug.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 3.
http://www.schwyz.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 4.
http://www.luzern.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 5.
http://www.schwyz.phz.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 6.
http://www.phvs.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 7.
http://www.phtg.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 8.
http://www.phsg.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 9.
http://www.phsh.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 10.
http://www.phr.ch
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 11.
http://www.hepfr.ch/
print() on closed filehandle OUTPUT at test_3.pl line 20, <INPUT> line 12.
http://www.phbern.ch                                                                            

好吧,我已经尝试了很多以消除错误以消除
一些思考:嗯-首先,我认为这不是一个非常严重的错误-我认为我必须对其进行调试,然后它会更好地工作。其次,我首先认为脚本似乎“使机器过载”?现在我对此不太确定:症状确实看起来很奇怪,但我想没有必要得出“机器过载”的结论 第三,我认为必须采取某些步骤来确保问题是完全与 WWW::Mechanize::Firefox 相关吗?这让我明白 Perl 警告的含义以及使用诊断编译指示获得更多解释的想法:你怎么看?

print() on unopened filehandle FH at -e line 1 (#2) (W unopened) An I/O operation was attempted on a filehandle that w +as never initialized. 

好吧 - 我们需要进行 open()、sysopen() 或 so +cket() 调用,或者调用 FileHandle 包中的构造函数

好吧 - 或者,关闭文件句柄 OUTPUT 上的 print() 也会给出很多答案,告诉我们我们没有使用 autodie,也没有检查 open 的返回值。我必须调试它并确保找到错误发生的位置

很抱歉这个新手问题,但我在谷歌上找不到我需要知道的东西。我理解 print ,但不明白这个......

4

1 回答 1

1

它是一个旧帖子,但没关系

我猜您没有权限在目录中写入文件。因此,如果您无法打开文件句柄,print()则无法写入文件句柄。

做类似下面的事情可能更合适

open(OUTPUT, ">$name") or die "Cannot open file...\n";
于 2012-07-14T03:53:02.910 回答