First of all you don't have to pass filehandles. You can use them like global variables. However, if you want to treat them like variables you could create an array of filehandles and pass that array. Or as you mentioned you wished not to send both the filename and filehandle the array could be global.
my @fhandle_array; for $filename (@filenames) { local *FILE; #so that FILE is limited in scope open(FILE, "$filename") or die "could not open file\n"; #push the filehandle into your filehandle array push(@fhandle_array, *FILE); }
To close the files simply either pass the array or make it global and use code similar to:
sub close_files() #args: none. uses global array: fhandle_array { my $handle; foreach $handle (@fhandle_array) { close $handle; } }
In reply to Re: Trouble Passing File Handles
by zek152
in thread Trouble Passing File Handles
by Photius
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |