pass a filehandle to a perl subroutine
May 4th, 2007 by Lawrence David
passing a filehandle to a subrouting in perl is slightly tricky; you’ll need to use an asterisk. for instance:
open (F, “/tmp/sesame”) || die $!;
read_and_print(*F);
sub read_and_print {
local (*G) = @_;Â # Filehandle G is the same as filehandle F
while () { print; }
}
c0b66bc93f4b…
c0b66bc93f4b65b2adb1…