perlquestion
Anonymous Monk
I am a new bie.. I have a file having 50,000 lines. I want to match a pattern. I read the whole file in an array and then match the regex. I want only the line with the first match. the code is something like :-
<CODE>
open( FILE, "file" ) || die ("The file not there ");
#open the file with 50,000 lines (some 1MB memory)
@list=<FILE>; # put this in an array.
close(DICTIONARY); # close the file
$regex="somebla.."; #this is the regex to be matched
@match=grep(/$regex/,@list);
#the above line returns an array of all lines matched
# but I want only first one !! Pity don't know how to
# get only that..
print $match[0];
#so I get the first match of the retrned array..
#that is poor .grep has to go through the complet list
# although I need the first match only
</CODE>
I request the help from perl monks..
With lot of thanks!!
Pandey
14