http://qs1969.pair.com?node_id=1162421

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

Greetings, Monks!
I'm attempting to create temporary links (prevent "hot linking"). So what I'm attempting, is to create a symlink on initiation, and set a timer (sleep / while) that when reached, unlinks the symlink. It all works just fine, except, that it sort of "hangs" the script/web page, while the timer is counting down. I first attempted this with the sleep function. But am now trying with a while(). Here's what I have now

#!/usr/bin/perl -w use strict; use feature qw(say); use POSIX qw(strftime); my $ctime= strftime "%H-%M", localtime; my $dlfile= "../PATH_TO/SOME_FILE"; my $dlname= "SOMENAME"; my $newname= "./ANOTHER_PATH/$ctime-$dlname"; my $maxtime= 30; my $args = ('-s'); print "content-type:text/html; charset=utf-8\n\n"; say qq~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" + /> <title>Download $dlname</title> </head> <body <h1>Download $dlname</h1> ~; system("/bin/ln $args $dlfile $newname"); while ($maxtime > 0) { $maxtime--; sleep(1); say qq~<a href="$newname">download</a>~; if ($maxtime == 0) { unlink $newname; say qq~<h3>Sorry! $newname no longer exists!</h3>~; } } say qq~<p> <br /> </p> </body></html> ~; exit
I'm sure this is really simple. But not for me, today. :/
Thanks, for any pointers!

--Chris

EDIT: fix a couple of typos. Move a block.

¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH