- my @skipper_with_name;
-
{
-
my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
-
@skipper_with_name = ('The Skipper', \@skipper);
-
}
We can create such a value directly using the anonymous
array constructor, which is yet another use for square brackets:
- my $ref_to_skipper_provisions =
-
[ qw(blue_shirt hat jacket preserver sunscreen) ];
The square brackets take the value within (evaluated in a list context); establish a new, anonymous array initialized to those values; and (here's the
important part) return a reference to that array.
- my @skipper_with_name = (
-
'The Skipper',
-
[ qw(blue_shirt hat jacket preserver sunscreen) ]
-
);
if we have this syntax:
- my $fruits;
-
{
-
my @secret_variable = ('pineapple', 'papaya', 'mango');
-
$fruits = \@secret_variable;
-
}
we can replace it with:
- my $fruits = ['pineapple', 'papaya', 'mango'];
- my %gilligan_info = (
-
name => 'Gilligan',
-
hat => 'White',
-
shirt => 'Red',
-
position => 'First Mate',
-
);
-
-
my %skipper_info = (
-
name => 'Skipper',
-
hat => 'Black',
-
shirt => 'Blue',
-
position => 'Captain',
-
);
-
-
my @crew = (\%gilligan_info, \%skipper_info);
- my @crew = (
-
{
-
name => 'Gilligan',
-
hat => 'White',
-
shirt => 'Red',
-
position => 'First Mate',
-
},
-
-
{
-
name => 'Skipper',
-
hat => 'Black',
-
shirt => 'Blue',
-
position => 'Captain',
-
},
-
);
阅读(454) | 评论(0) | 转发(0) |