Sample Code for perl constants, multi-dimensional arrays, and variable Initialization

Source: Internet
Author: User

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.

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.