in reply to Open Has a New Trick

I found this feature in the 5.8.0rc2 and made comment on it as a means by which to perform temporary file-type operations within memory space in this follow-up comment to my tutorial on Using Temporary Files in Perl.

Another nifty feature in 5.8.0 to do with the open function and temporary files is the creation of anonymous file handles. For example:

open( $fh, '+>', undef ) || die $!;

Where the undefined value is a literal undef statement, rather than an undefined variable. This syntax will open a file handle and where permitted by the file system, unlink the file while holding it open. The result is an anonymous STDIO stream which will be lost when the file handle is closed.

Note too that this anonymous file handle functionality is also available through the File::Temp module which has been incorporated into the core 5.8.0 distribution.

 

perl -e 'print+unpack("N",pack("B32","00000000000000000000000111000110")),"\n"'