Perl Learning Notes (5) the use of Glob

Source: Internet
Author: User
Tags glob
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>

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.