DavidSzczesniak
12/13/2017 - 2:28 PM

Filehandle References

Unlike scalars, arrays, hashes or functions, you can't reference a filehandle directly. That's because its not stored in a variable. Filehandles are objects of the class IO::File.

# You can call methods on them directly:
use autodie 'open';

open my $out_fh, '>', 'output_file.txt';
$out_fh->say('Have some text!');

# Old code might use IO::Handle, older code may take references to typeglobs:
local *FH;
open FH, "> $file" or die "Can't write '$file': $!";
my $fh = \*FH;