http://www.perlmonks.org?node_id=1030511

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

Greetings, I'm trying to discover if I can give a temporary file a "Life Span"
in Perl. Is such a thing even possible? My sutuation:
I'm generating a symlink (perlfunc=>symlink) that prefaces a semi-random
number to the $filehandle, thusly:
#!/usr/bin/perl -wT # testing with a web browser print "Content-type: text/html\n\n"; use strict; use POSIX qw(strftime); my $gmtstring = strftime "%H-%I-%S", localtime; my $filehandle = "relative/path/to/filename"; my $dir = "." if (-r $filehandle) { $filehandle = "readable"; }else{ $filehandle = "unreadable"; } if (-w $dir) { $dir = "writable"; }else{ $dir = "unwritable"; } unless ($filehandle && $dir) { symlink("$filehandle", "$gmtstring-$filehandle") }else{ print "$filehandle<br />$dir"; }
This much returns the anticipated/expected results. However,
I want the newly created symlink to "vanish" (perlfunc=>unlink)
after --say, a 10 minute period. Is there ANY way to tell Perl to unlink
the symlink -- like creating a timer, or something? I'm not sure where to go with
this. I could create a cronjob. But I would really rather keep
this "self-contained" if it's even remotely possible.

Thank you for all your time, and consideration.

--chris

UPDATE It also occurred to me that a session || sessions, might also be a solution.
In the "big picture" these "temporary" symlink(s), are largish files of complete systems for
embedded systems. I only want them to become available for those that actually want to use them --
not to embellish other ppl's web pages, and for "bots" to suck down ~50 times/day. So
it occurs to me that the "Life Span" of the file could be tied to a session.
Is that possible, or a better approach?

Thanks again.

#!/usr/bin/perl -Tw
use perl::always;
my $perl_version = "5.12.4";
print $perl_version;