### Code to print page # I am reading from another file and parsing what I want betweeen these 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 $temp_file: $!"; print FILE_IN ""; 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 "
PRINT THIS PAGE
"; #But my problem is here, I need to get rid of the $temp_file file, 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 $temp_file: $!"; undef $/; # Slurp mode $_ = ; my @temp_f=$_; my $tem_s=join("",@temp_f); close DEL_DATA; unlink($temp_file) || warn "Error removing $temp_file: $!"; }else{print "No match";}