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"; ; } # When this block ends, the enclose "scope" ends, and $fh is deleted print "Go check whether '$fname' was created (from a separate process) ...\n"; while (1) { sleep 3; print "Still here... (type ^C when finished)\n"; } #### 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"; ; undef $fh; # Undefine the filehandle and it will close automatically print "Go check whether '$fname' was created (from a separate process) ...\n"; while (1) { sleep 3; print "Still here... (type ^C when finished)\n"; }