+ -
当前位置:首页 → 问答吧 → 紧急求助:perl代码差错。多谢多谢啦!

紧急求助:perl代码差错。多谢多谢啦!

时间:2011-04-29

来源:互联网

说是有逻辑或语法错误,但是我都看不出来,觉得没啥问题,请有经验的TX指点下啦!多谢了!

There are errors in the following code, both in logic
and in syntax.  Find the errors and provide the correct
fixes.

# this function prints something to stdout, unless
# the option parameter is set to STDERR, and then it
# prints out to stderr
sub writeOut
{
  my $message = shift;
  my $option = shift;      #optional
    if( $option eq 'STDERR' )
  {
     print STDERR $message . "\n";
  }
  else
  {
     print $message . "\n";
  }
}


# this function gets the system UUID, with or without
# dashes depending on the option
sub getUUID()
{
   my $option = shift;     #optional

   my $uuid = "8f5de6fd-5f97-4b27-be35-861c3bbbb1f1";

   if( $option eq 'nodash' )
   {
      $uuid =~ s/-//g;
   }

   return $uuid;
}

作者: bubulife   发布时间: 2011-04-29

here

QUOTE:
sub getUUID()
{
   my $option = shift;     #optional

作者: zhlong8   发布时间: 2011-04-29

能请你进一步解释一下么?到底是哪里有错了?多谢啦!

作者: bubulife   发布时间: 2011-04-29

知道啦,你是说不应该有括弧是吧。

哎呀,真是糊涂了,我一直在想函数里面的语句没有问题啊!!!

多谢啦。

那第一段代码有什么问题呢?

作者: bubulife   发布时间: 2011-04-29

回复 bubulife


    第一个没什么问题,第二个你是用 () 声明了不需要参数,然后又在代码里面取参数。我从没这么用过,这个应该算逻辑错误吧

作者: zhlong8   发布时间: 2011-04-29

热门下载

更多