+ -
当前位置:首页 → 问答吧 → 初学者 $_的一个问题

初学者 $_的一个问题

时间:2011-06-18

来源:互联网

#!/usr/bin/perl
my $grid,%count,@locate;
for(1..10){
        $grid=int(rand 100);
        $count{$grid}++;
        redo if $count{$grid}>1;
}
@locate=keys %count;
for(1..100)
{
       $match=grep(/$_/, @locate);   #这里为什么$_的值为什么不是每次循环的值,而是1到100的所有值?应当如何解决?
       if (match!=0){     
              print "x ";
       }
       else {
               print ". ";
        }
        print "\n" if $_%10==0;
}
#这种代码风格有什么问题吗?因为是刚学perl,不对地方可以趁早改正,谢谢!

作者: bull_cattle   发布时间: 2011-06-18

好像有点儿问题~有点太随性了~其实Perl是很严谨的~

作者: x9x9   发布时间: 2011-06-18

回复 x9x9


    清具体谈谈好吗?不太懂,

作者: bull_cattle   发布时间: 2011-06-18

Code before strictures are enabled at line 2, column 1.  See page 429 of PBP.  Severity: 5

作者: ttcn_cu   发布时间: 2011-06-18