Hi Monks!

I need to delete a temp file created right after a link gets clicked, just can think how I could do that without having to submit all kinds of parameters back to the program, is there a way of doing that?
Any ideas, here is the code:

### Code to print page # I am reading from another file and parsing what I want betweeen thes +e tags if ($hold=~/<\?--printpg-->(.*?)<\/\?--printpg-->/gis) { my $page_to_print=$1; #generate freakyness here. my $freaky_number=int(rand(9999)) + 1; my $temp_file = "${curr_dir}".$freaky_number.".html"; # At this point I have the html page just the way I want, next +is to display it. open(FILE_IN, ">$temp_file") || warn "Can't open output file $t +emp_file: $!"; print FILE_IN "<body onLoad=\"self.print()\">"; print FILE_IN "$page_to_print"; close FILE_IN; # Here I am extracting just the file name out of the whole path if($temp_file =~/(.*?)\\([^\\]+)$/){ $file_hold=$2;} # Here I can send this page to the browser and it will open the + printer window automatically, it's done! print "<center><A HREF=\"javascript:void(0)\"onclick=\"window.o +pen('$file_hold','welcome','width=700,height=870')\">PRINT THIS PAGE< +/A></center>"; #But my problem is here, I need to get rid of the $temp_file fi +le, since I have to wait till the link to the #page to be printed is clicked I can't delete this file, I need + an idea on how to delete the file #right after the link gets clicked open(DEL_DATA, "$temp_file") || warn "Can't open output file $t +emp_file: $!"; undef $/; # Slurp mode $_ = <DEL_DATA>; my @temp_f=$_; my $tem_s=join("",@temp_f); close DEL_DATA; unlink($temp_file) || warn "Error removing $tem +p_file: $!"; }else{print "No match";}


Thanks for the Help!!!!

In reply to Deleting a Temp File by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.