Tables that manipulate CSV are often encountered in Perl processing files. Such a table resembles a two-dimensional array, so the actual operation of the two-dimensional array is done.For such rows and columns, we often need to follow a column, or
1. Read all the contents of the file into an array at once (this method is suitable for small files):
Copy Code code as follows:
Open (FILE, "filename") | | Die "Can not open the file: $!";
@filelist =;
foreach $eachline (@filelist)
1. Find existing Moduleshttp://search.cpan.org/
2. Input XML query, select the higher evaluation, and can meet their own needs of modules:Xml::simpleUse warnings;Use Xml::simple;Use Data::D umper;
#将XML文件转化为Hash结果
Copy Code code as follows:
Sometimes it is troublesome to encounter rows or columns that are inconsistent in length, although you can fill the file with the longest row (column) in R, but it is inconvenient, so remember to use Perl to achieve one.The indefinite length text
However, the common gadget of the Linux system is inherently friendly to the columns, sometimes invoking awk directly in Perl is more convenient and efficient than writing the corresponding Perl script. For example, insert the AWK statement with
1, single line (large file processing):
Copy Code code as follows:
My $oneline = or
while ($line =)
{ }
2, read all (small file processing):
Copy Code code as follows:
Open (My $in, "path") or Die
There is such a text file, the content has many lines as follows, the quantity is indefinite.Lif (__AMSCRIPT_CD ("Www.jb51.net")) {__AMSCRIPT_WC (' #closead {display:none;} ');Lif (__AMSCRIPT_CD ("Www.jb51.net")) {__AMSCRIPT_WC (' #footer_win
Let's see what the following code will output?
Copy Code code as follows:
My $a = 0;
$a = $a or 1;
Print $a, "\ n";
$a = $a | | 1;
Print $a, "\ n";
Output:01Why, then? because | |, =, or these three priorities are gradually
$ can also match \ n
See Introduction to Perl Language, page 132, note 6
Can 1/^.*$/match "\ n"? Yes! Because the $ can match not only the end of the line, but also \ nCan 2/^.*$/match "b\n"? Can be!. Can b match. \ n Match $Can 3/^.*$/match "\NB"?
asp.net|perl| Access | data | Databases asp.net/perl.net database access Example
One of the features of the. NET Framework is it ability to handle multiple languages. Third party compiler vendors can create and implement a compiler targeted for the.
Perl read files in two common ways to reprint the whole read-in, line-wise processing
Open (FILE, "@linelist =;
foreach $eachline (@linelist) {
Print $eachline;
}
Close FILE;
Read-by-line, edge-read edge processing
Open (FILE, "while ()
"Use POSIX": Sys_wait_h ";" Remove, and it is wrong to print the variables in the subprocess in the main process, the main process does not know the status of the child process, unless you pass the value of the variable to the main process with a
Regular Expressions in Perl
1. It is a wildcard and can match any single character, except for line breaks. If you want to use. In the mode, use /.
2. * match the first item zero or multiple times, such as/AB * C/match AC, ABC, abbbbbc...
3. +
1. ChildProgram(In common ?), It starts with "&" in a call to distinguish it from "$" and @2. the scalar in the subroutine block is global without any modification. This subroutine is called multiple times in a file and can be modified multiple
1. the array name can be the same as the scalar name. // if you are not afraid of being dizzy, use it =. =2. The array is out of bounds only when the value is UNDEF.3. underline only serves to divide long numbers4. The index value of the last
1. Write the code and # Run the CHMOD 755 file name directly.2. debugging is also possible, # Perl-M file name3. Transfer characters only play a role in double quotation mark strings, and scalar variable interpolation is also the same4. Use a scalar
1. $ where = index ($ big, $ small); the character position starts from 0. if the substring is found at the beginning of the string, index returns 0. if a character is followed, 1 is returned, and so on. if the substring does not exist,-1 is
1. Die "Oops! A file named '$ filename' already existed! "
If-e $ filename
Use the-E Option to check whether the file exists before the system creates a file.
2. Warn "config file is looking pretty old! /N"If-M config> 28; # config is a file
# Recently, I experienced Notes crash problems several times. # It wasted me a lot of time to terminate Notes completely and then restart it, # so I wrote this Perl script to save myself. Also hope it's helpful to you when you read these comments #
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