- my @names = qw{ zero one two three four five six seven eight nine };
-
my @numbers = @names [ 9, 0, 2, 1, 0 ];
-
print "Bedrock @numbers\n"; # says Bedrock nine zero two one zero
- my $new_home_phone = "555-6099";
-
my $new_address = "99380 Red Rock West";
-
@items[2, 3] = ($new_address, $new_home_phone);
- my @three_scores = ($score{"barney"}, $score{"fred"}, $score{"dino"});
-
the same with
-
my @three_scores = @score{ qw/ barney fred dino/ };
When you see something like @score{ ... } in a Perl program, you’ll need to do just as Perl
does and look at the at sign at the beginning as well as the curly braces at the end. The
curly braces mean that you’re indexing into a hash; the at sign means that you’re getting
a whole list of elements, not just a single one .
- @score{ @players } = @bowling_scores;
-
print "Their scores were: @score{@players}\n";
阅读(813) | 评论(0) | 转发(0) |