InMotion Web Site Hosting
InMotion Hosting Home




Node:Array Interpolation, Previous:The Context (List vs. Scalar), Up:Manipulating Arrays and Lists



Array Interpolation

Array variables can also be evaluated through interpolation into a double-quoted string. This works very much like the interpolation of scalars into double-quoted strings (see Scalar Interpolation). When an array variable is encountered in a double-quoted string, Perl will join the array together, separating each element by spaces. Here is an example:

use strict;
my @saying = qw/these are a few of my favorite/;
my $statement = "@saying things.\n";
         # $statement is "these are a few of my favorite things.\n"
my $stuff = "@saying[0 .. 1] @saying[$#saying - 1, $#saying]  things.\n"
         # $stuff is "these are my favorite things.\n"

Note the use of slices when assigning $stuff. As you can see, Perl can be very expressive when we begin to use the interaction of different, interesting features.


InMotion Web Hosting Customer Support
M-F 8am - 7pm PST
213-239-0050

More information can be found at the InMotion Hosting Main Site