Example 1:
Copy codeThe Code is as follows :#! /Usr/bin/perl
Use strict;
Use warnings;
My $ test = "asdf ";
Print "$ {test} _ test2 \ n ";
# Constant
Use constant {
AAA => "aaa ",
BBB => "bbb ",
MIN_TOTAL => 12,
SCORE_PASS => 90,
SCORE_RED => 70,
};
Print AAA;
Print SCORE_PASS;
# Two dimesion arrays
My @ steps = (
["Aaa", "aaavalue"],
["Bbb", "bbbvalue"],
["Ccc", "cccvalue"]
);
Print "\ n ";
Foreach my $ I (0 .. $ # steps ){
Print "$ steps [$ I] [0]: $ steps [$ I] [1] \ n ";
}
Code 2:
Copy codeThe Code is as follows: my $ a1;
Print "$ a1 \ n ";
My $ a2 = undef;
Print "$ a2 \ n ";
If (! Defined ($ a1) {print "a1 is not defined \ n ";}
If (! $ A2) {print "a2 is not defined \ n ";}
My $ a3 = '';
If (! $ A3) {print "a3 is empty string \ n ";}
Initialization is required when defining variables, or you need to determine whether the variable is defined during use. In many cases, you need to determine whether the variable is a null string. Especially when getopt: long or cgi-> query is used to obtain the parameter, check whether the parameter is defined. If yes, consider giving the default value.