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

おそらく、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 に答える
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 の本 (「Perl の学習」など) を読むために数日間話し合うことを強くお勧めします。

于 2013-10-02T09:49:59.897 に答える
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 に答える