【问题标题】:WWW::Mechanize::Firefox: debugging-attempt to stop print() on unopened filehandleWWW::Mechanize::Firefox: 调试-尝试在未打开的文件句柄上停止 print()
【发布时间】:2012-03-26 18:00:18
【问题描述】:

粉丝

抱歉这个新手问题,但我无法在谷歌上找到我需要知道的内容。我了解 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

在下面查看更多内容......

嗯 - 这是什么意思?

非常感谢您的耐心。

从头开始:好吧,我运行这个脚本,它是用来做一些网站截图的,我也已经启动并运行 mozrepl 在这里,我们有一些请求的 url 的文件......注意这只是真实列表的一个简短的 sn-p - 真实的列表要长得多。它包含超过 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 ,但不了解这个...

【问题讨论】:

    标签: debugging firefox printf mechanize www-mechanize


    【解决方案1】:

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

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

    做下面这样的事情可能更合适

    open(OUTPUT, ">$name") or die "Cannot open file...\n";
    

    【讨论】:

    • 非常感谢这个很棒的答案 - 这对我帮助很大!继续努力!
    猜你喜欢
    • 1970-01-01
    • 2012-04-10
    • 2015-03-05
    • 1970-01-01
    • 2018-06-23
    • 2015-12-04
    • 1970-01-01
    • 2010-11-01
    • 1970-01-01
    相关资源
    最近更新 更多