in reply to sharing filehandles
Update: *LogFile = *{shift()} also works.sub SetLog { my $glob = shift; *LogFile = *$glob; }
In general, though, I would avoid using barewords as file handles in this case and use scalars instead. "Advanced Perl" came out over 10 years ago, and a lot of practices have changed since then. (Update: I suppose you could have the 2005 edition, but still...) To pass file handles around it's just better to use scalar refs:
package test_a; my $LOGFH; sub SetLog { $LOGFH = shift; } sub TestLog { print $LOGFH "test_a::TestLog...\n"; } package main; ... test_a::SetLog(\*LOGF);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sharing filehandles
by Wiggins (Hermit) on Jun 29, 2008 at 23:52 UTC |