全局符号"$ i"需要明确的软件包名称 [英] Global symbol "$i" requires explicit package name

查看:274
本文介绍了全局符号"$ i"需要明确的软件包名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个数组,然后打开一个包含名,姓和电子邮件的txt文件(单独包含一些html代码,如下所示)

I have 3 arrays and then I open a txt file which contains firstname , lastname and email(alone with some html codes like shown below)

<first>Mike<first>
<sec>stone<sec>
<email>mike@rt.com<email>

我首先计算文件中的行数,然后解析此文件,并将first,last和email放入3个不同的数组中,然后从每个数组元素中删除htmls标签.但是我遇到了这样的问题,即使在删除html标签的过程中,全局符号在变量之一中要求显式包名称,即使我已经用它声明了它 这是代码段

I first count the lines in the file, then I parse this file and put first , last and email in 3 different arrays and then I remove the htmls tags from each array element. But I'm facing problems like Global symbol required explicit package name in one of the variable during removing the html tags even if I have declared it with my Here is the snippet

    if ( $ct <= $end ) {
        my $i = 0;
    }
    $ct++;
}

my $j = 0;
my $l = @lines;

while ( $j < $l ) {
      if ( $lines[$j] =~ m/@/ ) {
          50 $line[$i] = $lines[$j];

          51 $j = $j - 3;
          52 $last[$i] = $lines[$j];
          53 $j++;
          54 $first[$i] = $lines[$j];
          55 $i++;
          56 $j = $j + 7;
          57;
      }
      else 58 {
          59 $j++;
          60
      }

出现类似

Global symbol "$i" requires explicit package name at pqwe.pl line 50.
Global symbol "$i" requires explicit package name at pqwe.pl line 53.
Global symbol "$i" requires explicit package name at pqwe.pl line 55.
Global symbol "$i" requires explicit package name at pqwe.pl line 56.
Execution of pqwe.pl aborted due to compilation errors.

推荐答案

您需要将$i声明移出if块.检查以下代码:

You need to move the $i declaration out of the if block. Check below code:

#!/usr/bin/perl
use strict;
use warnings;

my $var = 1;

if ( $var eq 1)
{
    my $i = 100;
}

print $i."\n";

输出:

# perl test.pl 
Global symbol "$i" requires explicit package name at test.pl line 12.
Execution of test.pl aborted due to compilation errors.

现在,我将$i声明移出了if块:

Now, I moved the $i declaration out of if block:

#!/usr/bin/perl
use strict;
use warnings;

my $i;
my $var = 1;

if ( $var eq 1)
{
     $i = 100;
}

print $i."\n";

输出:

# perl test.pl 
100

在perl文档中了解有关此内容的更多信息: http://perldoc.perl.org /perlintro.html#Variable-scoping http://perlmaven.com/scope-of-variables-in-perl

Read More about it in the perl documentation: http://perldoc.perl.org/perlintro.html#Variable-scoping and http://perlmaven.com/scope-of-variables-in-perl

这篇关于全局符号"$ i"需要明确的软件包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆