I have two subroutines
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; }
and they are called like this:
$rfmain_beg=&get_first($rfmain[0]); $rfmain_end=&get_last($rfmain[$#rfmain]);
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.

Thanks in advance
Ted

UPDATE
Thanks using File::ReadBackwards worked nicely.

In reply to Speeding up Tie::File by tcf03

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.