On Wed, 26 Jun 2002 14:17:24 +0200, [EMAIL PROTECTED] (The Sequel) wrote: >Hello, > >I'd like to ask if anyone has a good general search algoritm to use for >plain text. The idea is, of cause, to get wildcards and typical boolean >operators in the algoritm. Maybe returning a array with matches in >descending order. I'm open to suggestions. Anyone has a close call? ;)
Here's a script that might get you started. The search pattern can be any regex, so you can search according to your regexing ability. Run it from the top dir you want to search. ##################################################### #!/usr/bin/perl # Recursively searchs down thru directories for pattern in files. # returns directory and line numbers too, and only searches text files. # usage zgrep 'search pattern' 'ext' (optional with no .) use warnings; use strict; use File::Find; my ($search, $ext) = @ARGV; if (defined $ext) {$ext = ".$ext"} else {$ext = '.*'}; die "Usage : greprz 'search' 'extension' (extension optional)\n" if ($search eq ""); @ARGV = (); find (sub { push @ARGV, $File::Find::name if (-f and -T and $ext or /\Q$ext$/)}, "."); while (<ARGV>) { close ARGV if eof; print "$ARGV: $. :$_\n" if /$search/; } ##################################################### -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]