### 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";}
In reply to Deleting a Temp File by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |