Instance code for Perl constants, multidimensional arrays, and initialization of variables _perl

Source: Internet
Author: User
Tags arrays

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.

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.