+ -
当前位置:首页 → 问答吧 → 路过的大侠帮我看看这些错误指的是什么?

路过的大侠帮我看看这些错误指的是什么?

时间:2011-02-20

来源:互联网

  1. foreach my $chro (keys %chro){
  2.         my $name = 'chro'."$chro";
  3.         my $coordi = 200+("$chro" - 1)*100;
  4.         print "$chro{$chro}->{"all_p"}\n";
  5.         $name = $svg->group("transform"=>"translate(30,"$coordi")");
  6.         my $long = 20 * "$chro{$chro}->{"all_p"}" / 1000000;
  7.         $name->rect('x',0,'y',0,'rx',2.5,'ry',2.5,'width',5,'height',"$long",'stroke','black','full','black');
  8.         my $cent_x = $long * "$chro{$chro}->{"cent"}" / "$chro{$chro}->{"all_g"}";
  9.         $name->ellipse('cx',2.5,'cy',"$cent_x",'rx',2.5,'ry',1.2,'fill','white');
  10. }
复制代码
其中foreach这行是原程序的第31行;
输出的错误信息为:
Scalar found where operator expected at plotchro.pl line 35, near ""translate(30,"$coordi"
        (Missing operator before $coordi?)
Bareword found where operator expected at plotchro.pl line 34, near ""$chro{$chro}->{"all_p"
        (Missing operator before all_p?)
String found where operator expected at plotchro.pl line 34, near "all_p"}\n""
String found where operator expected at plotchro.pl line 35, near "all_p"}""
syntax error at plotchro.pl line 35, near ""translate(30,"$coordi"
Global symbol "$long" requires explicit package name at plotchro.pl line 36.
syntax error at plotchro.pl line 38, near "my "
Global symbol "$cent_x" requires explicit package name at plotchro.pl line 36.
Execution of plotchro.pl aborted due to compilation errors.

看不太懂,改了半天,还是不行,
求路过的大侠指点,谢谢!

作者: 长生天一   发布时间: 2011-02-20

其中$chro,也就是从哈希里提出的key是数字1,2,3,...;
$chro{$chro}->{"all_p"}也是数字。

作者: 长生天一   发布时间: 2011-02-20

  1. foreach my $chro (keys %chro){
  2.         my $name = 'chro'.$chro;
  3.         my $coordi = 200+($chro - 1)*100;
  4.         print $chro{$chro}->{"all_p"}, "\n";
  5.         $name = $svg->group("transform"=>translate(30,"$coordi"));
  6.         my $long = 20 * $chro{$chro}->{"all_p"} / 1000000;
  7.         $name->rect('x',0,'y',0,'rx',2.5,'ry',2.5,'width',5,'height',$long,'stroke','black','full','black');
  8.         my $cent_x = $long * $chro{$chro}->{"cent"} / $chro{$chro}->{"all_g"};
  9.         $name->ellipse('cx',2.5,'cy',$cent_x,'rx',2.5,'ry',1.2,'fill','white');
  10. }
复制代码
试一下

作者: FenRagwort   发布时间: 2011-02-20

回复 FenRagwort

    非常感谢您的帮助,在您的基础上,去掉"translate(30,$coordi)"内$coordi两边的括号后,就可以了。
    我还是搞不明白,什么时候加"",什么时候不加""?
    ""号内的变量不是会被它的实际值替换么?
    我又感觉,不加引号的是数字,加了引号的是字符串。那 ""号内的变量被替换后,出来的是字符串呢?还是数字?

作者: 长生天一   发布时间: 2011-02-20