in reply to grep equivalent in perl
Please use <c> and </c> around your code, as you were told when you wrote your posting. Please update your existing posting now.
I think your problem is that you read the entire file into memory. That does not work well for large files.
To re-implement grep in perl, use open, a while loop wheat reads a file line by line, a pattern matching, and finally close. If you need to search more than one file, wrap that into another loop that iterates over all files to be searched.
Skeleton:
foreach my $fn (qw( /what/ever.file /another/file.txt /third/file/here + )) { open my $f,'<',$fn or die "Can't open '$fn': $!"; while (<$f>) { # <-- special case, RTFM chomp; # <-- you don't want the newlines, do you? if (/interesting/) { print "Found in line $. of file '$fn': $_\n"; } } close $f; }
Alexander
|
|---|