已尝试修改的只读值已开始显示在脚本

时间:2017-11-09 09:07:21

标签: perl

我试图解决为什么在Perl脚本中出现此错误:

A fatal error has occured:

    Modification of a read-only value attempted at (eval 7) line 10.

Please enable debugging in setup for more details.

当我从命令行运行它时:

perl -d admin.cgi

它死的点是:

<p><font face='Tahoma,Arial,Helvetica' size=2>A fatal error has occured:</font></p><blockquote><pre>Modification of a read-only value attempted at (eval 14)[/home/user/public_html/cgi-bin/links/admin/GT/AutoLoader.pm:128] line 10.
</pre></blockquote><p><font face='Tahoma,Arial,Helvetica' size=2>Please enable debugging in setup for more details.</font></p>
Modification of a read-only value attempted at (eval 14)[/home/user/web/example.com/public_html/cgi-bin/links/admin/GT/AutoLoader.pm:128] line 10.
Debugged program terminated.  Use q to quit or R to restart,

查看AutoLoader.pm文件,我在第128行看到了这一点:

eval "package $pkg;\n#line $linenum$pkg\::$func\n$COMPILE->{$func}";

如果我再添加一点调试:

print "FOO: $pkg ($func)\n";

我在跑步时看到了这个:

FOO: GT::Template (_call_func)
FOO: GT::CGI (html_escape)
FOO: GT::Base (in_eval)
<p><font face='Tahoma,Arial,Helvetica' size=2>A fatal error has occured:</font></p><blockquote><pre>Modification of a read-only value attempted at (eval 7) line 10.
</pre></blockquote><p><font face='Tahoma,Arial,Helvetica' size=2>Please enable debugging in setup for more details.</font></p>
Modification of a read-only value attempted at (eval 7) line 10.

这个剧本整个昨天工作得很好,我不认为我改变了会引起这种情况的任何事情 - 所以我有点不知所措。

更新经过多次挖掘,我发现它来自另一个模块的这一行:

my $output = $code->($self);

$code似乎来自以上几点:

my $root      = $self->{root};
my $full_file = $self->{root} . '/' . $template;
my ($code, $dont_save, $files) = $self->{opt}->{print} == 2
    ? @{$FILE_CACHE_PRINT{$full_file}}{qw/code dont_save files/}
    : @{$FILE_CACHE{$full_file}}{qw/code dont_save files/};

更新2: 根据要求,这是print STDERR qq|package $pkg;\n#line $linenum$pkg\::$func\n$COMPILE->{$func}\n|;的输出:

package GT::Base;
#line 538GT::Base::in_eval
sub in_eval {
# -------------------------------------------------------
# Current perl has a variable for it, old perl, we need to look
# through the stack trace. Ugh.
#
    my $ineval;
    if ($] >= 5.005 and !MOD_PERL) { $ineval = defined($^S) ? $^S : (stack_trace('GT::Base',1) =~ /\(eval\)/) }
    elsif (MOD_PERL) {
        my $stack = stack_trace('GT::Base', 1);
        $ineval = $stack =~ m{
            \(eval\)
            (?!
                \s+called\ at\s+
                (?:
                    /dev/null
                |
                    -e
                |
                    /\S*/(?:Apache2?|ModPerl)/(?:Registry(?:Cooker)?|PerlRun)\.pm
                |
                    PerlHandler\ subroutine\ `(?:Apache2?|ModPerl)::Registry
                )
            )
        }x;
    }
    else {
        my $stack = stack_trace('GT::Base', 1);
        $ineval   = $stack =~ /\(eval\)/;
    }
    return $ineval;
}


<p><font face='Tahoma,Arial,Helvetica' size=2>A fatal error has occured:</font></p><blockquote><pre>Modification of a read-only value attempted at (eval 7) line 10.
</pre></blockquote><p><font face='Tahoma,Arial,Helvetica' size=2>Please enable debugging in setup for more details.</font></p>
Modification of a read-only value attempted at (eval 7) line 10.

1 个答案:

答案 0 :(得分:1)

啊男人 - 找到了!在网站配置中,它有这个奇怪的东西:

'db_cgi_url' => \'http://m.example.com/cgi-bin/links',
'db_cgi_url.' => \'http://m.example.com/cgi-bin/links',
'db_cgi_url..' => \'http://m.example.com/cgi-bin/links',
'db_cgi_url...' => \'http://m.example.com/cgi-bin/links',
'db_cgi_url....' => \'http://m.example.com/cgi-bin/links',
'db_cgi_url.....' => \'http://m.example.com/cgi-bin/links',
'db_cgi_url......' => \'http://m.example.com/cgi-bin/links',
'db_cgi_url.......' => \'http://m.example.com/cgi-bin/links',
'db_cgi_url........' => \'http://m.example.com/cgi-bin/links',
'db_cgi_url.........' => \'http://m.example.com/cgi-bin/links',
'db_cgi_url..........' => \'http://m.example.com/cgi-bin/links',
'db_cgi_url...........' => \'http://m.example.com/cgi-bin/links',

其他地方的东西必须更新它,而不是我要求它。不在mod_perl下的前端似乎没问题,因为它使用的是Data.pm的缓存版本

谢谢大家!