Free Perl Tutorials

How To Delete A File In PERL

Deleting a file in perl is a very simple task. It isn't like the copy function where you have to worry about adding a PERL module to your coding. Nope! This is just good old fashioned coding!

Here is the code to delete a file using PERL:


unlink "test.txt";


What is the PERL code doing?
"unlink" is telling PERL to delete the file named "test.txt" file.

Not exactly the longest bit of PERL coding in the world, but effective nonetheless! Just make sure that you are deleting the correct file when using PERL. If you cut and paste a lot of code, it's easy to overlook the file name you want to delete and delete the wrong file. Don't ask how I know this!