in reply to Sending filehandles?
The "normal" way of achieving this is to use a lexical filehandle:
open(my $FILEHANDLE, ">", $filename) or die "Could not open file: $!"; print $FILEHANDLE "This goes to \$filename, as normal"; mysub( $FILEHANDLE );
I've used the 3-argument form of open, and included $! in die. That'll let perl tell you what the problem is rather than just "Could not open file".
$FILEHANDLE can be passed to a subroutine, just like any other variable.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sending filehandles?
by djp (Hermit) on Feb 11, 2008 at 02:28 UTC | |
by DrHyde (Prior) on Feb 12, 2008 at 11:07 UTC | |
by djp (Hermit) on Feb 13, 2008 at 05:24 UTC | |
by DrHyde (Prior) on Feb 13, 2008 at 10:47 UTC |