Greetings Monks:
I am atempting to open a temporary file <TMP> using File::Temp. The goal is to to write the contents of $page to the temp file.Next I would like to write a conditional statement that is dependant upon an regex.When the regex is finished reading I want the temp file to disappear.
The following code looked to me like it might do the right thing however, the while (<TMP>) loop seems uneffective.
Guidance Appreciated
sub captured{
my ($page,$addy) =shift @_;
use File::Temp qw(tempfile unlink0 );
use vars qw($fh $filename);
my $template = 'tempXXXXXXXXXX';
my $dir = '/tmp/';
($fh, $filename) = tempfile($template, DIR => $dir)
or die " Error creating $filename: $!";
print "\nCreated file $filename.\n";
open (TMP, "+< $filename")
or die "Error opening $filename for WO: $!";
print TMP "$page"
or die "Error writing to $filename: $!";
while (<TMP>){
my $header=$_;
print "$header";
#if ($header=~/^\<TITLE\>Target String Here\<\/TITLE\>$/){
print "$addy is a page of interest\n";
}
close (TMP)
or die "Error closing $filename: $!";
unlink0 ($fh, $filename)
or die "Error unlinking file $filename safely: $!";
}