Example 1:
Copy Code code 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 Code code as follows:
My $a 1;
print "$a 1\n";
My $a 2 = undef;
print "$a 2\n";
if (!defined ($a 1)) {print "A1 is not defined\n";}
if (! $a 2) {print "A2 is not defined\n";}
My $a 3 = ';
if (! $a 3) {print "A3 is empty string\n";}
When you define a variable, you must initialize it, or if you are using it to determine if it is defined, and many times you need to decide whether it is an empty string. In particular, when you use Getopt::long or cgi->query to obtain a parameter, you want to detect whether it is defined or not, if there is a definition to give the default value.