local(*FH);
But while still supported, that wasn't the best to go about getting local
filehandles. Typeglobs have their drawbacks. You may well want to use the FileHandle
module, which creates new filehandles for you (see the FileHandle manpage):
use FileHandle; sub findme { my $fh = FileHandle->new(); open($fh, "</etc/hosts") or die "no /etc/hosts: $!"; while (<$fh>) { print if /\b127\.(0\.0\.)?1\b/; } # $fh automatically closes/disappears here }
Internally, Perl believes filehandles to be of class IO::Handle. You may use that module directly if you'd like (see Handle), or one of its more specific derived classes.