"Perl language entry" self-study notes - Chapter 3 1
Mainly some of the introductions and skills of some arrays and lists, can fully feel the convenience and power of Perl :)
Array:
1. Array is a count from 0.
2. See the index value of the last element: $ # rocks
3. Simple questions: Rocks [-1]
Interval operators indicate the list direct quantity:
(1..5): Represents 1, 2, 3, 4, 5
(1.7..5.7): Indicates 1, 2, 3, 4, 5 decimal to be removed
(5..1): Empty list, only one online
QW shortcuts to indicate the direct quantity of the list:
Qw / Fred Barney Betty Wilma Dino / DILMA DINO /
Qw {
/ usr / local / words
/Home/rootbeer/.ispell_ENGLISH
}
The list can be easily defined by the QW operator, and the front and rear operators can be defined by themselves.
The list assignment:
($ FRED, $ Barney, $ Dino) = ("Flintstone", "Rubble", undef;
Method for variable transformation:
($ FRED, $ barney) = ($ Barney, $ FRED);
Array assignment:
@ Rocks = Qw / bedrock slet lava /;
Array copy:
@ Rocks = @ Copy
POP and PUSH operators:
The POP function takes out the last element of an array and returns it:
@ array = 5..9;
$ FRED = POP (@Array); # $ FRED gets 9, @ array now has (5, 6, 7, 8)
$ FRED = POP @Array; # $ fred Get 8, brackets are not the same, @ array now (5, 6, 7)
The Push function adds an element in the array
Push (@ array, 0); # @Array has (5, 6, 7, 0)
Push @ array, 8; # @Array has (5, 6, 7, 0, 8)
Push @ array, 1..10; # @Array adds 10 new elements
Shift and unshift functions:
Operate the beginning of the array, similar to POP and PUSH;
@ Array = QW # Dino Fred Barney #;
$ a = shift (@Array); # $ a gets Dino, @ array now has ("fred", "barney");
Unshift @ array, 4; # @Array now has 4, Fred, Barney