相关疑难解决方法(0)

为什么这个程序有效?我试图创建一个语法错误

我在Windows 7上运行ActiveState的32位ActivePerl 5.14.2.我想用Git预提交钩子来检测正在检查的语法错误的程序.(不知怎的,我只是设法做了这么糟糕的提交.)所以作为一个测试程序,我随机记下了这个:

use strict;
use warnings;

Syntax error!

exit 0;
Run Code Online (Sandbox Code Playgroud)

但是,它在没有警告的情况下编译和执行,退出时errorlevel为零.这个有效的语法怎么样?

perl

487
推荐指数
5
解决办法
2万
查看次数

使用 WWW::Mechanize 进行内存泄漏

我在 Perl 中有这个脚本"Out of memory",运行几分钟后出现错误。我看不到任何循环引用,我无法弄清楚为什么会发生这种情况。

use feature 'say';
use WWW::Mechanize;
use HTML::TreeBuilder::XPath;
use utf8;

$url = "some url";

my $mech = new WWW::Mechanize;
$mech->get($url);
my $html = HTML::TreeBuilder::XPath->new_from_content($mech->content);
my $html2;

do { 
    for $item ($html->findnodes('//li[@class="dataset-item"]'))
    {
        my $title = $item->findvalue('normalize-space(.//a[2])');
        next unless $title =~ /environmental impact statement/i;        
        my $link = $item->findvalue('.//a[2]/@href');
        $mech->get($link);
        $html2 = HTML::TreeBuilder::XPath->new_from_content($mech->content);
        my @pdflinks = $html2->findvalues('//a[@title="Go to external URL"]/@href');
        my $date = $html2->findvalue('//tr[th="Date Created"]/td');
        for $pdflink (@pdflinks)
        {
            next unless $pdflink =~ /\.pdf$/;
            $mech->get($pdflink);
            $mech->save_content($filename …
Run Code Online (Sandbox Code Playgroud)

perl out-of-memory www-mechanize

4
推荐指数
1
解决办法
154
查看次数

小写“begin”是 Perl 关键字吗?

我在 Linux Debian 下运行 Perl 脚本版本 5.28,并带有一些实验性的“扩展”,并出现了奇怪的行为。在混合 Pascal-SQL-Perl 编程会话中,我错过了在 if-else 语句中输入小写字母begin而不是 an else(请参阅下面的测试代码),并得到了有效但出现故障的代码。

我知道大写BEGIN关键字属于BEGIN, UNITCHECK, CHECK, INIT and END程序“程序运行前和程序运行后”组。但我使用了小写begin变体,并且得到了有效的运行代码。在我看来,该begin {...}块是在if (...) {...}表达式之后单独执行的,这会导致不必要的提前返回。

小写字母begin在 Perl 区分大小写的编程上下文中有任何意义吗?

#!/usr/bin/perl
use v5.20;
use strict;
use warnings;
use feature qw(signatures);
no warnings 'once';
no warnings 'experimental';
no warnings 'experimental::signatures';

&if_exotic(1000);
&if_normal(1000);

# --------------------------------------
# Bad variant
# --------------------------------------
sub if_exotic($want) {

   if ($want>0) {
       print "BAD: ..running $want operations\n";
   } …
Run Code Online (Sandbox Code Playgroud)

perl keyword

3
推荐指数
1
解决办法
101
查看次数

标签 统计

perl ×3

keyword ×1

out-of-memory ×1

www-mechanize ×1