Perl‎ > ‎

Lists

Lists or Arrays

Creation:

my @first_fibs = (1, 1, 2, 3, 5, 8, 13, 21);
my @chars = 'a' .. 'z';
my @count = 13 .. 27;

. . . and you may use the qw() operator to split a literal string on whitespace to produce a list of strings:

my @stooges = qw( Larry Curly Moe Shemp Joey Kenny );

. . . as targets of assignments:

my ($package, $filename, $line) = caller();

. . . or as lists of expressions:

say name(), ' => ', age();




Empty the array

@my_array = ();


count the elements of the array

my $count = () = get_the_hats();



Comments