Perl’s filesystem functions let you manipulate files and directories on the server from within your CGI scripts. This means that you can:
- store data in files on the server
- allow visitors to upload files to your site
- create message boards and guestbooks
…and all sorts of other useful stuff!
In this tutorial, we’ll show you how to create files and write to them, how to read from them, how to delete them, and how to scan directories (folders) so that you can see what files are on the server.
We’ll also discuss file and directory permissions, and the concept of full paths. At the end of the tutorial you’ll find a useful script to help you work out your full paths (essential for working with files).
This tutorial will also touch on some other Perl concepts such as while loops, lists, and appending strings to variables. It’s quite a long tutorial, but worth sticking with. By the end of it you’ll have learnt a lot of useful concepts, and you’ll be able to write your own CGI scripts to read and write files on your server!