in reply to module which tells more warning about FILHANDLE
The easiest way is to use a module like IO::File, and either undefine the filehandle when you're finished writing to it, or have it close automatically when it goes out of scope.
Here's one way (going out of scope):
use strict; use warnings; use IO::File; # Create a new filehandle, and write to 'file.txt' my $fname = "file.txt"; { my $fh = new IO::File($fname, ">"); print $fh "Here's a single line of text\n"; # Close the file once the user types [RETURN] print "Type [RETURN] to close file ...\n"; <STDIN>; } # When this block ends, the enclose "scope" ends, and $fh is delet +ed print "Go check whether '$fname' was created (from a separate process) + ...\n"; while (1) { sleep 3; print "Still here... (type ^C when finished)\n"; }
And here's another (explicit deletion using undef) ...
use strict; use warnings; use IO::File; # Create a new filehandle, and write to 'file.txt' my $fname = "file.txt"; my $fh = new IO::File($fname, ">"); print $fh "Here's a single line of text\n"; # Close the file once the user types [RETURN] print "Type [RETURN] to close file ...\n"; <STDIN>; undef $fh; # Undefine the filehandle and it will close automati +cally print "Go check whether '$fname' was created (from a separate process) + ...\n"; while (1) { sleep 3; print "Still here... (type ^C when finished)\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: module which tells more warning about FILHANDLE
by jettero (Monsignor) on Dec 28, 2006 at 02:54 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |