james28909 has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks, I am back, and come with a question regarding opening a file with undef as the filename.

open (my $fh, '+>', undef);

What exactly is this doing? I ask this because I was able to read and write to $fh as if it were a real file. Is it a temp file somewhere on the harddrive? Or is it in memory

Replies are listed 'Best First'.
Re: Open with 'undef' filename.
by BrowserUk (Patriarch) on Nov 07, 2016 at 00:14 UTC
    From perlfunc:open
    As a special case the 3-arg form with a read/write mode and the third argument being undef: open(my $tmp, "+>", undef) or die ... opens a filehandle to an anonymous temporary file.

    I believe the term "anonymous temporary file" is related to this on *nix. I know nothing more about that.

    On Windows it creates a very ordinary file in the users home directory with a name of plx????.tmp where ???? are 4 hex digits. And those files are automatically delete when the process ends.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Thanks for the explanation.