richard@pegasus.com (Richard Foulk) (08/29/90)
I need to search a large file or two for a text string. What is the fastest way to search a large file for the first occurance of some random string and return its location? Nothing I've tried has been very fast. Thanks. -- Richard Foulk richard@pegasus.com
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (08/30/90)
In article <1990Aug29.003742.16051@pegasus.com> richard@pegasus.com (Richard Foulk) writes: : I need to search a large file or two for a text string. What is the : fastest way to search a large file for the first occurance of some : random string and return its location? Something like this, assuming you feed it real filenames. As a filter, you'd have to keep track of position yourself. #!/usr/bin/perl $text = shift; $text =~ s/(\W)/\\$1/g; eval <<EOF; while (<>) { print("\$ARGV: pos ", tell(ARGV)-length, "\\n"),close ARGV if /$text/; } EOF In a little while I'll have the o modifier be as fast, but not yet. Larry