0
my $refer = $ENV{HTTP_REFERER};
 my $gk1 = substr($str1, -4); 
if ($gk1 = .swf) { my $antigk = "gk detected"; } 
else 
{ my $antigk = $link; }

这段代码有什么问题?编辑后出现一些错误:|

是我的第一个 perl 代码,所以:| 我不知道我做错了什么:|

难道是因为那个

my $antigk

?

THIS is my new error:
Software error:

Global symbol "$str1" requires explicit package name at index_dl.pm line 680.
syntax error at index_dl.pm line 682, near "= ."
syntax error at index_dl.pm line 683, near "else"
Global symbol "$antigk" requires explicit package name at index_dl.pm line 684.
Global symbol "$direct_link" requires explicit package name at index_dl.pm line 684.
syntax error at index_dl.pm line 727, near "}"
Can't use global @_ in "my" at index_dl.pm line 731, near "= @_"
syntax error at index_dl.pm line 735, near "}"
syntax error at index_dl.pm line 761, near "}"
syntax error at index_dl.pm line 779, near "}"
index_dl.pm has too many errors.
For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.

Status: 500 Content-type: text/html
Software error:

[Wed Oct  2 20:40:40 2013] fast_index_dl.cgi: Global symbol "$str1" requires explicit package name at index_dl.pm line 680.
[Wed Oct  2 20:40:40 2013] fast_index_dl.cgi: syntax error at index_dl.pm line 682, near "= ."
[Wed Oct  2 20:40:40 2013] fast_index_dl.cgi: syntax error at index_dl.pm line 683, near "else"
[Wed Oct  2 20:40:40 2013] fast_index_dl.cgi: Global symbol "$antigk" requires explicit package name at index_dl.pm line 684.
[Wed Oct  2 20:40:40 2013] fast_index_dl.cgi: Global symbol "$direct_link" requires explicit package name at index_dl.pm line 684.
[Wed Oct  2 20:40:40 2013] fast_index_dl.cgi: syntax error at index_dl.pm line 727, near "}"
[Wed Oct  2 20:40:40 2013] fast_index_dl.cgi: Can't use global @_ in "my" at index_dl.pm line 731, near "= @_"
[Wed Oct  2 20:40:40 2013] fast_index_dl.cgi: syntax error at index_dl.pm line 735, near "}"
[Wed Oct  2 20:40:40 2013] fast_index_dl.cgi: syntax error at index_dl.pm line 761, near "}"
[Wed Oct  2 20:40:40 2013] fast_index_dl.cgi: syntax error at index_dl.pm line 779, near "}"
[Wed Oct  2 20:40:40 2013] fast_index_dl.cgi: index_dl.pm has too many errors.
Compilation failed in require at ./fast_index_dl.cgi line 53.
For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.
4

3 回答 3

1
# In this line you store the HTTP referer in the variable $refer
my $refer = $ENV{HTTP_REFERER};

# Then, in this link you take a substring of the variable $str1.
# But you don't have a variable called $str1.
# Perhaps you actually wanted to take a substring of $refer?
my $gk1 = substr($str1, -4); 

# This next line will be a syntax error because you need to quote
# strings (and .swf is a string. This should be '.swf'.
# Also, you are using '='. This is the assignment operator. This
# will set $pgk1 to the value '.swf'. That's not what you want to do.
# You want to compare $pgk1 and '.swf'. For that you need the comparison
# operator - which is 'eq'.
# So this whole line should be:
# if ($gk1 eq '.swf') {
if ($gk1 = .swf) {
  # It's good that you are declaring $antigk using 'my'. But 'my' only
  # works within a code block. So you're setting $antigk here, but the
  # value will be lost as soon as you pass the end of the code block
  # (which is the '}' on the very next line).
  # Better to declare $antigk (with 'my $antigk') before the 'if' statement.
  my $antigk = "gk detected";
} else {
  my $antigk = $link;
}

一般来说,你在这里犯了一些非常基本的编程错误。我假设您认为通过跳入问题和谷歌搜索帮助您学得最好。我不认为这种方法对你有用。在继续这个项目之前,我强烈建议花几天时间来完成一本 Perl 初学者书籍(如“Learning Perl”)。

于 2013-10-02T09:49:59.897 回答
1

您可能在index_dl.pm文件顶部附近有这个:

use strict;

这意味着您需要在my使用之前声明每个变量:

my $str1;

您可能想$antigk在 if-else 块之前声明,也许您真的想要:

my $antigk = $link;
if ($gk1 eq '.swf') { $antigk = "gk detected"; } 
else 
{ $antigk = $link; }
于 2013-10-01T19:37:31.730 回答
0

除了工具的答案,我想你必须改变这些行:

my $refer = $ENV{HTTP_REFERER};
my $gk1 = substr($str1, -4); 

对这些:

my $refer = $ENV{HTTP_REFERER};
my $gk1   = substr($refer, -4); 
#                  ^^^^^^
于 2013-10-02T07:23:15.157 回答