In our last series of tutorials we worked with Conditionals and Loops to create some basic Perl programs. This time around we are going to be working with files. Text files, CGI files, PL files, boiled files, fried files, Files Benedict, steamed Files. Okay, so I was kidding about the steamed Files.
Creating a file to read from in Perl is pretty simple. Simply open up a .txt file and enter the following data:
The Incredible Hulk|Super Strength|I rip my pants
Daredevil|Heightened Senses|I have poor fashion sense due to blindness
Apache Chief|the ability to grow Very Tall|I Wear a skirt
When you enter the data, note a few things. First, there are no headers here. Second, we separate each column of data with a pipe(|) symbol. And third, each line of data is separated by pressing the Enter key. Note that nothing should appear on the blank lines, not even a space. This is because when Perl reads it, it will read that line as a new row of data.
When you finish entering the data, save the file. You can leave it as a .txt file if you like. The only downside to this is that the data will be visible to any users who happen upon your page. If you want to limit visibility of the data, you can save it as a .cgi or .pl file, depending upon your host. For simplicity's sake, save the file (use the name super.txt) in the same directory as you are saving your script. If you don't, you will have to point to the directory where your file is being saved.
At this point we could set permissions, but I will save that for another time. Setting permissions allows you to choose whether the file can only be read, can be edited, neither, or both.