Hi All,

I have one requirement, the file content is following, it is a dynamic
file,

1194240905.451    105 127.0.4.56 TCP_MISS/200 2853 GET
cache_object://localhost/info - NONE/- text/plain
1194240905.452      0 127.0.0.1 TCP_MISS/200 2853 GET
cache_object://localhost/info - NONE/- text/plain
1194240905.452      0 127.0.0.1 TCP_MISS/200 2853 GET
cache_object://localhost/info - NONE/- text/plain


First time read the full file, then store byte position of the line
before the last line read and last line time stamp(eg: 1194240905.452)
in to one temporary file.

next time first open the temporary file and get the position,time stamp.
open the file and seek the position of last time read and get time stamp
of current line, after comparing that time stamp with already stored
time stamp, if both are equal then doing some calculation..


I have tried as below, but it not works well,

#!/usr/bin/perl
use strict;
use warnings;
use Tie::File;

my($name,$pos,$name1,$no,$tmpp,$tmp);
my $file="/file/path";
open(FH,"temp.txt");
while(<FH>)
{
($pos,$name1)=split;
}
close FH;
tie my @file, 'Tie::File', 'test.txt' or die $!;
my $length=$#file + 1;
untie @file;
open(FH,"$file");
seek(FH,$pos,0);
while(<FH>) {
($Ltimestamp,$Lelapsed,$Lhost,$Ltype,$Lsize,$Lmethod,$Lurl,$Luser,
$Lhierarchy,$Lconttype)=split;
         if(($Ltimestamp eq $name1)
            {
               #some calculation
            }
if($.== ($length-1))
{
$tmpp=$_;
}
}
my ($na,$num)=split(" ",$tmpp);
$pos=tell(FH) if/^$na/;
close FH;
open(FH,">temp.txt");
print FH "$pos $na";
close FH;


Reply via email to