分类:
2007-02-21 11:50:03
eg
sub max {
$max = (@_);
foreach $foo (@_) {
$max = $foo if $max < $foo;
}
$max;
}
$bestday = max($mon,$tue,$wed,$thu,$fri);
例:%fruit_color = ("apple", "red", "banana", "yellow");等价于%fruit_color = (
apple => "red",
banana => "yellow",
);
and
.@fruits = %fruit_colors; @colors = %fruit_colors;
此类型的特例:%ENV 包含些环境变量
一个包含三种类型的较为复杂的变量$,@,%
my $variables = {
scalar => {
description => "single item",
sigil => '$',
},
array => {
description => "ordered list of items",
sigil => ,
},
hash => {
description => "key/value pairs",
sigil => '%',
},
};
7、Variable scoping
之前的变量定义前均有加my,这个不是必须的。但是如前面使用了use strict,则必须加。
关于变量就学习到这里,下一章节将学习条件语句