tcf03 has asked for the wisdom of the Perl Monks concerning the following question:
and they are called like this:sub get_first { # usage: get_first("firstfile"); my $f1=shift; # first file tie my @file1, 'Tie::File', "$workdir$f1" or die("Can't tie $f1: $ +!\n"); my $first=@file1[0]; untie @file1; my ($dow, $month, $day, $time, $year, $line)=split(/\s+/, $first); my $start_time=join ' ', $month,$day,$year,$time; return $start_time; } sub get_last { # usage: get_last("lastfile"); my $f2=shift; # last File tie my @file2, 'Tie::File', "$workdir$f2" or die("Can't tie $f2: $ +!\n"); my $last=@file2[$#file2]; untie @file2; my ($dow, $month, $day, $time, $year, $line)=split(/\s+/, $last); my $end_time=join ' ', $month,$day,$year,$time; return $end_time; }
where @rfmain holds a list of file names. The problem is that this takes a very long time, the files are about 120 - 220 meg each. I just need the very first line of the first file and the very last line of the last file. These are log files and each line begins with a date. Is there a better way of doing this? Ive looked around, but Tie::File seems to be mentioned quite a bit.$rfmain_beg=&get_first($rfmain[0]); $rfmain_end=&get_last($rfmain[$#rfmain]);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Speeding up Tie::File
by dragonchild (Archbishop) on Apr 11, 2005 at 17:54 UTC |