Perl Learning 0517

Source: Internet
Author: User
Tags foreach

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.