Perl constants + multi-dimensional arrays + variable Initialization

Source: Internet
Author: User

Code:

 

Use Strict;
Use Warnings;

My $ Test="ASDF";
Print "$ {Test} _ Test2 \ n";

#Constant
UseConstant {
AAA =>"Aaa",
Bbb =>"Bbb",
Min_total =>12,
Score_pass =>90,
Score_red =>70,
};

PrintAAA;
PrintScore_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:

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.

 

Complete!

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.