Perl knowledge point

Source: Internet
Author: User

I have been using Perl for my recent work.Program. Although Perl is not my learning direction, I still summarize some knowledge points I encountered at work for future use.

1. Define a hash (hash or associated array)
% For = (
"AAA" => "001 ",
"BBB" => "002 ",
"CCC" => "003 ",
"DDD" => "004 ",
);

2. Use $ for {"AAA"}, or use the simple variable $ for {$ tmp_par }.

Define a two-dimensional join Array
% For1 = (
"AAA" => "001 ",
"BBB" => "002 ",
"CCC" => "003 ",
"DDD" => "004 ",
);
% For2 = (
"XXX" => "how ",
"Yyy" => "are ",
"Zzz" => "you ",
);

% To_for = (
"0" =>/% for1,
"1" =>/% for2,
);

/Is used to get the addresses of % for1 and % for2.
In this way, you can use$ To_for {"0" }{ "AAA "}001.

3. Recursively call a subroutine in Perl. The subroutine must stop calling itself.CodeSuch as the return statement. In addition, except for variables not changed by the quilt program, all variables must be partially declared using my.

4. Split () ?,., +, * And other characters must be separated by escape/, for example:Split ('/? ', $ Some_string );

5. Put the split string in the array:My @ Temp=Split ('/', $ tmp_s2 );
Then you can use @ temp to get the array size, for example:My $ size = @ temp;$ Size is the temp size of the array.
 
6. Array loop:
Foreach my $ U (@ arr_tmp)
{
...
}

7. Determines whether a string matches a mode. $ u = ~ is available ~ /Tre | world | MP3/
For example:My $ pattern = "Tre | world | MP3"
If ($ u = ~ /$ Pattern /)
{
# Matching
}

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.