Chinaunix首页 | 论坛 | 博客
  • 博客访问: 966334
  • 博文数量: 184
  • 博客积分: 10030
  • 博客等级: 上将
  • 技术积分: 1532
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-27 18:32
文章分类

全部博文(184)

文章存档

2009年(1)

2008年(63)

2007年(39)

2006年(79)

2005年(2)

我的朋友

分类:

2006-10-20 16:15:08

第一个程序:
#! /usr/local/bin/perl -W
#fig06_07.pl
@array=scalarOrList();
$"="->";  # set default separator character
print "Return: \n@array\n";
print $";
print "\nReturned: " . scalarOrList(), "\n";

sub scalarOrList {
   if(wantarray()) {
      return 'this','is','a','list','of','strings';
   }
   else {
      return 'hello';
   }
}

输出如下:
Return:
this->is->a->list->of->strings
->
Returned: hello

第2个程序:
#! /usr/local/bin/perl -W
#fig06_07.pl
@array=scalarOrList();
$"="->";  # set default separator character
print "Return: \n@array\n";
print $";
print "\nReturned: " ,scalarOrList(), "\n";

sub scalarOrList {
   if(wantarray()) {
      return 'this','is','a','list','of','strings';
   }
   else {
      return 'hello';
   }
}
输出如下:
Return:
this->is->a->list->of->strings
->
Returned: thisisalistofstrings

差别仅在于一个是 "." 一个是","
阅读(1288) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~