Perl pop Push Shift Unshift Instance introduction _perl

Source: Internet
Author: User
Learn to record
Copy Code code as follows:

#!/usr/bin/perl-w
Use strict;
The values of print ' @a @b @c @d are 1 2 3 ', ' \ n ';
My @a = (1..3);
Pop (@a);
The value of print "\@a is the @a,pop to take off the rightmost value of the array \ n";
My @b = (1..3);
Push (@b, ' 4 ');
The value of print "\@b" adds a value to @b,push to the far right of the array. \ n ";
My @c = (1..3);
Shift@c;
The value of print "\@c" is @c,shift to remove the leftmost value of the array. \ n ";
My @d = (1..3);
Unshift (@d,0);
The value of print "\@d" adds a value to @d,unshift to the leftmost of the array. \ n ";


[Root@otrs perl]# Perl pop_push_shift_unshift.pl
The value of @a @b @c @d is 1 2 3.
The value of @a is 1 2,pop the rightmost value of the array is removed
The @b value is 1 2 3 4,push Add a value to the rightmost of the array.
The value of @c is 2 3,shift the leftmost value of the array is removed.
The @d value is 0 1 2 3,unshift Add a value to the leftmost of the array.
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.