Skip navigation.
Home
Your source for Perl tips, howto's, faq and tutorials

removing files

( categories: )

Use the unlink function. You can specify either a single file or a list of files to delete. Here are some examples:

#remove a single file
unlink "file.old";
 
#remove a list of files
@file_list = ( "file1.txt¨, "file2.txt", "last.file" );
unlink @file_list;
 
#remove all files ended in .bak
unlink <*.bak>;

NOTE:
- unlink does not remove directories, use rmdir instead


checking for file existence and/or other attributes

( categories: )

Use the -X operator, where X can be any of the letters listed below:


opening files

( categories: )

- Open a file for reading:

open(FH, "<filename");

- Open a file for writing (truncating the file if it exists):

open(FH, ">filename");

- Open a file for writing in appending mode:

open(FH, ">>filename");

- Open a file for reading and writing:

open(FH, "+<filename");


Syndicate content