in reply to Perl fIle handles

1) Always include the following at the top of your code:

use strict; use warnings; use 5.010; #if you are using perl 5.10 or greater

2) Don't use bareword file handles, like here:

open SHAKESPEARE, "complete_works.txt" or die "The haunted grave of Shakespeare won't open: $!";

A bareword filehandle is like a global variable, and global variables are bad because any part of your code can change a global variable, which makes debugging very difficult.

3) The following is called a 'typeglob':

*someName
A typeglob represents every perl variable with the name someName. Remember that in perl, these are all different variables:
$x -- scalar @x -- array %x -- hash &x -- subroutine (as well as a filehandle named x)

You can have all those variables in your program at the same time and there is no conflict. A typeglob is a reference to all of them. Once again, a typeglob is too much like a global variable, so generally you shouldn't use them for filehandles. Typeglobs are an intermediate to advanced topic.

4) Despite wind's recommendation, I would suggest that you always use the 3-arg form of open. If you want to read from a file, and you use the 2 arg form of open like this:

my $file = 'out.txt' open my $sh, $file or die ...

that will work fine. But suppose you are opening all the files in a directory, and $file gets set to the filename ">out.txt", well now you have a problem because the 2 arg form of open is going to open that file for writing. Sometimes it's better to be explicit with what you want to do in your code than rely on perl's implicit workings behind the scenes.