Re: What is an "anonymous temporary file?" (question about PerlFAQ5)
- From: xhoster@xxxxxxxxx
- Date: 28 Jun 2005 19:54:49 GMT
usenet@xxxxxxxxxxxxxxx wrote:
> PerlFAQ5 (v5.8.7) says:
>
> >>> How do I make a temporary file name?
>
> >>> If you don't need to know the name of the file, you can use open()
> >>> with undef in place of the file name. The open() function creates
> >>> an anonymous temporary file.
>
> >>> open my $tmp, '+>', undef or die $!;
>
> I'd like to know more about this...
>
> What is an "anonymous temporary file?" The name suggests (to me) that
> it is a "file" in memory (or virtual memory) only. Am I correct?
I would say you are not correct, but one could interpret virtual memory
to include both ram and disk in their totallity, so in that sense you would
be correct.
It is in memory to pretty much the same extent any other open file with the
same usage would be in memory.
> Or, is this an actual file on an actual filesystem? (ie, something you
> could test with -f if you knew the name?)
It is an actual file on an actual filesystem, but you inherently don't
know the name, as it doesn't have one. You could call -f on it's
filehandle, I suppose.
> If so, what filesystem?
> (how does Perl decide?)
I don't know how it decides, but it makes the wrong decision for me.
Rather than figure out how to change it's decision, I just explicitly make
a temp file, get it's handle, and then immediately unlink the file.
> I did a test on my machine - I opened a file like this, dumped a bunch
> of data to it, and then slept the script. I didn't see any indication
> of an actual disk-based temporary file in the usual places (/tmp,
> /var/tmp, $HOME, etc).
What kind of indication did you look for?
$ perl -le 'system "df -k"; open my $fh, "+>", undef or die $!; print $fh
"x"x1e6 foreach 1..5000; system "df -k"'
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda5 110610112 77740360 27251020 75% /
/dev/hda3 101107 88835 7051 93% /boot
none 1030576 0 1030576 0% /dev/shm
[rest elided]
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda5 110610112 82636052 22355328 79% /
/dev/hda3 101107 88835 7051 93% /boot
none 1030576 0 1030576 0% /dev/shm
[rest elided]
Notice that filesystem / is about 5 gig fuller than it used to be.
>
> Does Perl automatically "clean up" such temporary files when they go
> out of scope?
No, linux automatically cleans them up. (Well, if you are running on
Linux).
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.
- References:
- Prev by Date: Re: Perl format string
- Next by Date: Re: calculating a list..
- Previous by thread: Re: What is an "anonymous temporary file?" (question about PerlFAQ5)
- Next by thread: Perl format string
- Index(es):
Relevant Pages
|
|