第一个程序:
#! /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
差别仅在于一个是 "." 一个是","
阅读(1318) | 评论(0) | 转发(0) |