in reply to Is it possible to "use vars" or "our" a file handle?
Try:
3-arg open is nicer and safer, using the variable twice solves the warning, and by my'ing it, you can pass it around and have it go out of scope.my $fileHandle; #Closes for you when it goes out of scope! open $fileHandle, '>', $fileName or die "Can't open $fileName: $!\n"; writeFancyLogging($fileHandle, "Loggin' some stuff to a file"); sub writeFancyLogging { my $file = shift; my $msg = shift; print $file $msg . "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is it possible to "use vars" or "our" a file handle?
by rovf (Priest) on Nov 02, 2009 at 16:04 UTC | |
|
Re^2: Is it possible to "use vars" or "our" a file handle?
by rovf (Priest) on Nov 02, 2009 at 16:07 UTC |