我试过这段代码.这不起作用.我输出没有结果.我犯了什么错误?
my %fruit_color = ("apple","red","banana","yellow"); my @fruits = keys %fruit_colors; my @colors = values %fruit_colors; print @fruits; print @colors;
解决方法
您正在声明fruit_color但引用fruit_colors(注意尾随的S)
如果你使用了警告和限制,你会注意到这一点.
use warnings; use strict; Global symbol "%fruit_colors" requires explicit package name at C:\temp\test.pl line 4. Global symbol "%fruit_colors" requires explicit package name at C:\temp\test.pl line 5.