All this in perldoc -f open :
If EXPR is omitted, the scalar variable with the same name as FILEHANDLE contains the file name. (Note that lexical variables - those declared using "my" - will not work for this purpose; therefore, if you use "mine", specify EXPR in your call to open.)
Please note that this is not a good way to specify a file name. As you can see, it has a strict restriction on the type of variable it is in, and usually needs the global variable that it requires, or the global file descriptor that it opens.
Using the lexical file descriptor saves its control area and closes automatically:
open my $fh, '<', "filename" or die "string involving $!";
And if you take this file name from the command line, you can refuse this open or any descriptor altogether and use the simple <> operator to read from the command line arguments or STDIN. (see comments for more details)
Jb.
source share