I. Condition Determination
If ( ){
}
Elsif ( ){
}
...
Else {
}
Ii. Loop:
1. While Loop
While ( ){
}
2. Until Loop
Until ( ){
}
3. For Loop of class C, such
For ($ COUNT = 1; $ count # Statements inside the loop go here
}
The following is an
I. Definition
Child
Program That is, to execute a separate section of a special task
Code It can reduce repeated code and make the program readable. In Perl, subroutines can appear anywhere in the program. Definition method:
Sub subroutine
Basically, a simple variable is a data unit, which can be a number or string.I. Integer1. IntegerThe most common simple variables in Perl are not described here because they are basically the same as other languages.Example:$ X = 12345;If (1217 + 116
Perl starts to use utf8 encoding internally to represent characters starting from 5.6. That is to say, there should be no problem in processing Chinese characters and other language characters. We only need to make good use of the encode module to
1. What is Perl Hash?
A hash is a data structure. Similar to an array, a hash can store a value or retrieve the value from it. However, unlike an array, its index is not a number but a name. That is to say, the index (here we call it key) is not a
Requirement: Take a row in file 1 and compare it with all the data in file 2. Save the row in the same way. Otherwise, delete the row.
Copy codeThe Code is as follows :#! /Usr/bin/perl
# Use strict;
Open (FILE1, "C:/Perl/BX/BX-Users.txt ");
Open
Even if the strict and warnings options are enabled, the following code does not have errors or warnings.
Copy codeThe Code is as follows :#! /Usr/bin/perl
Use strict;
Use warnings;
Sub test {
$ A = 1;
$ B = 2;
Print $ a, "\ n ";
Print $ B, "
A routines call in CGI. pm
1. CGI. pm implements two usage methods: Object-oriented method and traditional perlmodule method.Object-Oriented Approach:
Copy codeThe Code is as follows :#! /Usr/local/bin/perl-w
Use CGI; # load CGI routines
$ Q = CGI->
With the in-depth development of network security requirements, network-based intrusion detection technology has become an important and interesting research direction. The best way to learn NIDS is to write an NIDS program by yourself, in addition
Why use references?
In perl4, the value field in the hash table can only be scalar, not list, which is inconvenient in some cases, such as the following data:Chicago, USAFrankfurt, GermanyBerlin, GermanyWashington, USAHelsinki, FinlandNew York,
Operations such as csv are frequently encountered in perl processing files. Such a table is similar to a two-dimensional array, so operations on the two-dimensional array are actually performed.For such a row and column table, we often need to sort
Open a file using the Open () function
Common methods to open a file are:
Copy codeThe Code is as follows: open (FH, "Or die "Couldn't open $ filename for reading: $! ";
The open () function usually has two parameters. The first is the file handle,
Basic usage
# Initialize % h as an empty array % h = {};# Use an array to initialize % h as a => 1, B => 2% h = ('A', 1, 'B', 2 );# The meaning is the same as above. It is just a more Visualized Method. % H = ('A' => 1, 'B' => 2 );# If the key is a
Sometimes it is troublesome to encounter different lines or columns with different lengths. Although you can fill the file in R with the longest rows (columns), it is inconvenient, so I think of using perl to implement one.A text file of an
However, awk, a commonly used tool in linux, is naturally friendly to Column Operations. Sometimes it is more convenient and effective to call awk directly in perl than to write the corresponding perl script. For example, use system to insert an awk
1. Open and Close files
The return value of open is used to determine whether the file is successfully opened. If the file is successfully opened, a non-zero value is returned, and zero is returned if the file fails. Therefore, the following
Read files:
Copy codeThe Code is as follows :#! Perl
Open filetxt, "/path/a.txt"; # filetxtis the file handle and is used to establish a link with file a.txt. The file handle can be named at will, but it should not be the same as several file
$ Can also match \ n
For more information about Perl, see page 132. Note 6.
1/^. * $/can it match "\ n? Yes! Because $ not only matches the end of a row, but also matches \ n2/^. * $/can it match "B \ n? Yes !. B matches. \ n matches $3/^. * $/can
I. Special variables of Regular Expressions
1. $ n: contains the nth substring of the last pattern match.2. $ &: String matched in the previous successful mode3. $ ': Content Before the successful substring4. $ ': content after the child string that
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.