[ Please quote some context when replying. ]
File handles are in global scope. You can open them in one function
and use them in a different function or main.
Just because you *can* do something doesn't mean that you should do it.
Why would you want to cause coupling between the name you choose for
your the file handle, and all of the subroutines that use it. If you
change the name of the file handle in one place, then you have to go
find the other N places where it also needs to be changed.
So, if you have an alternative to bareword file handles, you use it:
open my $input_fh, '<', $filename
or die "Cannot open $filename: $!";
mysub($input_fh);
etc ...
On the other hand, if you do not have lexical file handles (because you
have to cater to much older versions of Perl), you can still do:
#! /usr/bin/perl
use strict;
use warnings;
open FILE1, '>', 'file1' or die "Cannot open file1: $!";
open FILE2, '>', 'file2' or die "Cannot open file2: $!";
hello ($_) for (*FILE1, *FILE2);
goodbye($_) for (*FILE1, *FILE2);
close FILE2 or die "Cannot close file2: $!";
close FILE1 or die "Cannot close file1: $!";
sub hello { print $_[0] "Hello\n\n"; }
sub goodbye { print $_[0] "... Goodbye!\n"; }
__END__
Please do read the posting guidelines for this group.
Sinan