Perl Learning notes-Directory operations

Source: Internet
Author: User
Tags glob

Move in the catalog book

ChDir Changes the current working directory. It is similar to the CD command in the Shell :

ChDir '/etc ' or die "cannot chdir to/etc:$1";

Note: The working directory cannot be changed, meaning that the Perl program will return to its working directory.

If chdir is called without arguments,Perl will guess that it wants to go back to the user's home directory and set the working directory to the home directory, which is used without parameters under the shell. the cd command works the same.

Note: You cannot use tilde ~.

File name wildcard

Form:echo *.pm; where wildcard characters are * . The same applies in Perl:

My @all_files =glob ' * ';

My @pm_files =glob ' *.pm ';

where@all_files gets all the files in the current directory and sorts them alphabetically, but does not include files that begin with a dot, which is exactly the same as the practice in the shell (LS) .

Another syntax for file wildcard

Use <> complete glob functions, such as:

My @all_files =<*>;# effect is equivalent to : my @all_files =glob "*";

Perl Learning notes-Directory operations

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.