Hello jayu_rao,
Here are two possible solutions:
(1) Create the temporary file using the core module File::Temp and get the filename together with the handle:
use File::Temp 'tempfile';
...
my ($fh, $filename) = tempfile();
my $bw = File::ReadBackwards->new($filename)
or die "Cannot read '$filename' backwards";
while (my $log_line = $bw->readline)
{
...
}
(2) Use the File::ReadBackwards TIED HANDLE INTERFACE, which accepts a filehandle:
my $filename = 'data.txt';
open(my $bw, '<', $filename)
or die "Cannot open file '$filename' for reading";
tie *$bw, 'File::ReadBackwards', $filename
or die "Cannot read '$filename' backwards";
while (my $log_line = <$bw>)
{
...
}
(Note the asterisk in tie *$bw — this is required. Also note the two different ways of reading the next line from the file: readline vs. <$bw>. N.B.: they are not interchangeable!)
Hope that helps,
|