What are lists?
- A list is an ordered set of scalar data
- An array is a variable that holds a list
List literals
- (1,2,3) is a list
with three values: 1, 2 and 3.
- ("Perl", 15.4) has
two values: "Perl" and 15.4.
- () is an empty list,
with zero values
- Lists can also contain variables, which are expanded at runtime.
my $name = "Andy";
my $addr = "alester\@fsc.follett.com";
my $phone = "x7660";
my @info = ( $name, $addr, $phone )
# @info is now ( "Andy", 'alester@fsc.follett.com', "x7660" )
Future changes to $name, $addr and $phone will have no
effect on @info. List
shortcuts: the .. construct
- .. defines a range
- (1..10) is the same
as
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10
) List
shortcuts: quotewords
- qw() is for quoting
short words.
- Instead of
( "This", "That",
"Other" ) you can use qw( This That Other ) or even qw( This That Other );
- Note there are no commas. If you use them, they'll be in your
values.
|
|
|