in reply to module which tells more warning about FILHANDLE

Just let the filehandle get closed when you're done with it.

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"; }

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

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
    It would seem that given the new (to me) my in open you don't even need IO::File anymore...
    use strict; my $in; SCOPE: { open my $in, "/etc/passwd" or die $!; print "", scalar <$in>, "\n"; } print "(nothing?): ", scalar <$in>, "\n";

    -Paul

A reply falls below the community's threshold of quality. You may see it by logging in.