in reply to Specified Line Searching in file!

Four Megabytes isn't a BIG-BIG file, unless you're still using a Commodore-64 computer or a PC-XT. You should be able to loop your way through the file reading line by line, and disposing of the line if it's irrelevant before moving onto the next one, like this:

my( $found, $lineno ); while ( <DATA> ) { if ( /keyID/ ) { $found = $_; $lineno = $.; print "Found $found at line $lineno.\n"; last; } }

That ought to get through your file in pretty short order, and won't consume copious amounts of memory.


Dave

Replies are listed 'Best First'.
Re^2: Specified Line Searching in file!
by brionius (Sexton) on Jul 29, 2004 at 20:09 UTC
    i agree with Dave here, i have search like this that takes a 30MB file running on a 500mhz G4 and it handles it in about 7 seconds with the system doing various other things. no need to get too crazy unless you're in a really performance intensive situation.