1. chdir change the working directory... chdir "/etc" or die "cannot chdir to/etc: $! "; If the parameter is null, change it to the main directory.
2. My @ all_files = glob "*"; my @ bz_file = glob "*. bz2"; only
3. My @ all_files = <*>; my $ dir = "/etc"; my @ dir_files = <$ DIR/* $ DIR/. *>;
4. If there is a strict (simple) identifier between the angle brackets, it is the file handle reading operation; otherwise, it is the globbing operation.
5. If the directory name is not added, the test part will only detect the files in the current directory, rather than the files under $ dirname. This is the most common use of directory handles.
Errors
6. Use unlink with caution when deleting files...
7. Rename, rename "old", "new ";
8.Foreach my $ file (glob "*. Old") {<br/> my $ newfile = $ file; <br/> $ newfile = ~ S //. old $ /. new/; <br/> If (-e $ newfile) {<br/> warn "can't rename $ file to $ newfile: $ newfile exists/N "; <br/>} elsif (rename $ file, $ newfile) {<br/>## success, do nothing <br/>} else {<br/> warn "RENAME $ file to $ newfile failed: $! /N "; <br/>}< br/>}
Batch rename
9. In rare cases, you can use the utime function to trick other programs into the latest file modification time and access time.
The first two parameters provide the recent access time and modification time. The remaining parameters are the list of files whose values need to be changed.
My $ now = time;
My $ ago = $ now-24*60*60;
Utime $ now, $ ago, glob "*";
Update all files in the current directory so that they seem to have been modified yesterday, and the access time is now.