The meaning of the offset parameter in the ##################### #read () function
Read (FILEHANBD, $var, $length, $offset)
The read function has four parameters, most easily misunderstood is the $offset
It means to look at the official document and explain:
An OFFSET may is specified to place the read data at some place in the string other than the beginning. A Negative OFFSET Specifies placement at this many characters counting backwards from the end of the string. A positive OFFSET greater than the length of SCALAR results in the string being padded to the required size with "a" byte S before the "the" read is appended.
The cost of the
#################### #优化技巧 function is significant.
a loops to call a function
B loop through a function
performance, B is better than a.
#################### #glob的用法-Read all files in a directory
1. For example, to read all the files in the/home/globtest directory, you can write this: @plFiles = Glob '/ Home/globtest/*.* ';
The glob used above is equivalent to
Opendir (dir, "/home/globtest"); #注意这是在Linux的写法, if you are under Windows, it should be written as Opendir (dir, "f:\\home\\ Globtest ");
@Files =readdir (Dir);
Closedir (Dir);
foreach $Cur (@Files) {
$File = "/home/globtest". $Cur;
Open (in, $File);
while (<IN>) {
...
}
Close (in);
}
2 . @many = Glob "{apple,tomato,cherry}={green,yellow,red}";
The output of the @many array will be visible:
1 apple=green
2 apple=yellow
3 apple=red
4 tomato=green
5 Tomato=yellow br> 6 tomato=red
7 cherry=green
8 cherry=yellow
9 cherry=red
br>