Assigning values to lists
($fred, $barney) = ($barney, $fred); Swap the values of these two variables
@ references the entire array.
Note: When copying an array to another array, it is still the assignment of the list, but these
The list is stored in an array.
@copy = @quarry; #将一个数组中的列表复制到另一个数组
Pop and push operators
@array = 5..9;
$fred = Pop (@array); # $fred becomes 9, @array is now (5,6,7,8)
$barney = Pop (@array);
Pop @array;
Push (@array, 0); # @array is now (5,6,0)
Push (@array, 8); # @array is now (5,6,0,8)
Push (@array, 1..10); # @array got 10 new elements
@others = QW/9 0 2 1 0/;
Push @array, @others; # @array got 5 new elements (19 total)
Shift and UNSHIFT operators
The "Start" of the array is processed accordingly.
Splice operator
Array interpolation in a string
foreach Control structure
#foreach $rock (Qw/bedrock slate lava/)
#{
# print "One rock is $rock. \ n";
#}
@rocks = Qw/bedrock Slate lave/;
foreach $rock (@rocks)
{
$rock = "\t$rock";
$rock. = "\ n";
}
Print "The Rocks are:\n", @rocks;
Perl's favorite default variable: $_
foreach (1..10)
{
Print "I can count to $_!\n";
}
Reverse operator