Alexandr Ciornii
Alexandr Ciornii

Reputation: 7390

file location from IO::File

IO::File->new_tmpfile returns IO::File object which points to file. Is it possible to get file location on Windows?

Upvotes: 0

Views: 518

Answers (1)

Ivan Nevostruev
Ivan Nevostruev

Reputation: 28753

You can achieve this with File::Temp:

my $fh = File::Temp->new();
my $fname = $fh->filename;

In case of IO::File, getting temp file name doesn't look possible. Source of IO::File shows that only OutputStream is stored in the object:

void
new_tmpfile(packname = "IO::File")
    const char * packname
    PREINIT:
    OutputStream fp; ## it doesn't look like you can get file name out of this
    GV *gv;
    CODE:
#ifdef PerlIO
    fp = PerlIO_tmpfile();
#else
    fp = tmpfile();
#endif
    ...

As far as I know not all streams have file name associated with it (for example pipes).

Upvotes: 7

Related Questions