- 论坛徽章:
- 0
|
For example, consider the bowling scores set individually:- $score{"fred"} = 205;
- $score{"barney"} = 195;
- $score{"dino"} = 30;
复制代码 This seems rather redundant, and in fact can be shortened to:- ($score{"fred"},$score{"barney"},$score{"dino"}) =
- (205,195,30);
复制代码 But even these seems redundant. Let's use a hash slice :- @score{"fred","barney","dino"} = (205,195,30);
复制代码 There. Much shorter. We can use a hash slice with variable interpolation as well:- @players = qw(fred barney dino);
- print "scores are: @score{@players}\n";
复制代码 |
|