Re: Pattern matching problem



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
.



Relevant Pages

  • Re: Finding the nearest match without reusing results
    ... comparing an array with a value generates an array of Trues and ... Any diff with wrong State or with used Store is implicitly zeroed out. ... Each must be larger than the absolute value of the maximum Sales ... go.....it just needs to return the closest match. ...
    (microsoft.public.excel.programming)
  • Re: read keyboard input and storing in an array?
    ... > I'm trying to store user input in an array, ... You have the beginnings of that logic already since your prompt tells the ... 201st value since the array only has room for 200 values. ... This will force you to store the int values as Integer ('Integer' ...
    (comp.lang.java.help)
  • Re: Challenge: reading ascii data
    ... to store all the data before producing any output. ... would be bad practice in terms of memory consumption to use a standard ... So I use hashes to create a two-level "sparse array", ... Well the original problem definition was: ...
    (comp.lang.fortran)
  • Re: attempting an actual game...
    ... >>> and inflexible by the absurd decision to use a bit array for square ... as then one has 8 bits in which to store a color and a few flags ... Using a 2D int (or, ... > Change direction and you may eventually complete a game. ...
    (comp.games.development.programming.misc)
  • Re: Sparse arrays
    ... >access array element, set it, sit for a bit, and read it back ... ONLY operations are STORE and RETRIEVE with no structure to the ... If you can tolerate a bit of inefficiency ... They live in sorted lists. ...
    (comp.lang.fortran)