Anirban Adhikary wrote:

Subject: Pattern matching problem

As far as I can tell, this is not a pattern matching problem.

I have a very large file basically it is logfile generated by sql
loader......... In the production environment this file can have one
million/ two million data. In this  file there are 4 particular lines which
i need to extract from this log file.

*Total logical records skipped:          0
Total logical records read:          4830
Total logical records rejected:        51
Total logical records discarded:     4760
*
These four lines stayed at the bottom of the. Now if I use a filehandel to
open the file and stored it contents in an array

Why would you store its contents in an array? Typically you read a file line by line.

and after that I make a
search to find these 4 lines then it will take lot of times to get output.
So is there any other way where I dont need to store the file in a array and
I can directly search the file and when I find these lines I can store these
lines in some array or variables.

This is how you can read the file line by line:

    open my $fh, '<', 'sql.log' or die $!;
    while ( <$fh> ) {
        print if substr($_, 0, 13) eq 'Total logical';
    }

Since the file is large, and you know that what you are looking for is near the end of it, you can use the seek() function to speed up the process.

    open my $fh, '<', 'sql.log' or die $!;
    seek $fh, -500, 2 or die $!;
    while ( <$fh> ) {
        print if substr($_, 0, 13) eq 'Total logical';
    }

See "perldoc -f seek".

An alternative is to make use of the module File::ReadBackwards.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to