我创建了以下子程序性别来随机打印字符串 MALE 或 FEMALE。当调用子程序时,打印命令在字符串末尾添加一个“1”后缀。请参阅下面的示例代码和输出:
sub gender {
if ( (int rand(100)) >50) {
print "MALE ";
}
else {
print "FEMALE";
}
}
foreach (1..5) {
print &gender, "\n";
}
请注意,“1”后缀为“MALE”或“FEMALE”
输出:
FEMALE1
FEMALE1
MALE 1
MALE 1
FEMALE1
MALE 1
我正在使用perl v5.8.9 v5.8.9
为 MSWin32-x86-multi-thread 构建
Binary build 826 [290470] provided by ActiveState http://www.ActiveState.com Built May 24 2009 09:21:05