The use of the angle bracket operator in Perl (">") _ Application Tips

Source: Internet
Author: User
Tags stdin

The <> operators in Perl can be used for the following purposes:

1 if the middle of the angle bracket is a file handle, the angle bracket operator allows you to read the file handle, such as <STDIN>.
2 If the middle of the angle bracket is a search pattern, the angle bracket operator can return a list of files that match the pattern, which is called a glob, such as < *.bat>.
3 A set of angle brackets operator If there is nothing in the middle, it can read the contents of all the files on the command line, and if no file name is given, you can read the standard output.

Take a look at the following code:

Copy Code code as follows:

while (<>) {
Print $_;
}

If you save the above program as example.pl, run the program with the following command line:

Copy Code code as follows:

#perl –w example.pl file1 file2 file3

You can make the operator <> read the contents of the file1, read 1 rows at a time, read the file2, and then read the File3.
If no file is set, the angle bracket operator reads the data from the file handle stdin.

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.