App-Relate
view release on metacpan or search on metacpan
my @search_terms = @ARGV;
($DEBUG) && print STDERR "$prog running on: ", Dumper( \@search_terms ), "\n";
my $result = relate( \@search_terms, $skipdull, $opts );
foreach my $line (@{ $result }) {
print $line, "\n";
}
### end main, into the subs
sub say_usage {
my $usage=<<"USEME";
$prog <-options> <arguments>
TODO fill-in usage statement
USEME
print "$usage\n";
exit;
}
sub say_version {
print "Running $prog version: $VERSION\n";
exit 1;
}
# Read in config file "~/.relate" *or* create it if it doesn't exist
# (Allows easy editing of default settings later).
sub get_config_from_dot_file {
my $default_config = shift;
my $dot_file = "$HOME/.relate";
my $config = {};
if ( -f $dot_file ) {
undef $/;
open my $fh_in, '<', $dot_file or die "$!";
my $dot_code = <$fh_in>;
eval "$dot_code";
if ( $@ ) {
croak "Problem with eval of $dot_file...:$@";
}
} else {
open my $fh_out, '>', $dot_file or die "$!";
$config = $default_config;
print {$fh_out} Data::Dumper->Dump( [ $config ], [ qw(config) ] );
}
return $config;
}
__END__
=head1 DESCRIPTION
The mnemonic is that B<relate> makes the file system a little
more relational and a little less hierarchical (but L<relate isn't really>).
Instead of typing this:
locate this | egrep "with_this" | egrep "and_this" | egrep -v "but_not_this"
You can just type:
relate this with_this and_this -but_not_this
So essentially this script is the equivalent of
locate primary_term | egrep term2 | egrep term3 [....| termN]
Though it also has a few other features, B<relate>:
o screens out "uninteresting" files by default (emacs backups, CVS/RCS files)
o has options to restrict reports to files, directories or symlinks.
An important performance hint: you can speed up relate
tremendously by using a relatively unique first term. For
example, if you're on a unix box, you don't want to start
with something like "home" or "lib" which is going to match
a huge number of files in the locate database. You'll find
that "relate gdk lib" is faster than "relate lib gdk".
The first term should be a simple string (unless you've used the
"-r" option), but all the following terms are perl regexps.
If you do use the "-r" option, than the first term is a POSIX
regexp (it has no effect on the following terms).
(This inelegant state of affairs is the result of working as a
wrapper around the locate command; the first term is fed to it
directly, then the output is filtered using perl pattern
matches.)
=head2 reverse match
A leading minus can be used to indicate a reverse match
(just as with many web search engines). This is much like a
"grep -v": it filters out lines that match it.
This can't be used on the first term, only on the secondary ones.
For example:
relate my_site index -htm$
will screen out files ending in "htm" (but not "html").
=head2 standard filter
This script has the extremely useful feature of automatically
omitting uninteresting files, but it's guaranteed that you'll
be confused by this some day, so don't say I didn't warn you.
Remember that there's a "-a" option (also called "--all")
which overrides the default filter and returns all matches.
As of this writing, by default files are ignored that match
these patterns:
'~$' # emacs backups
'/\#' # emacs autosaves
',v$' # cvs/rcs repository files
'/CVS$'
'/CVS/'
'/RCS$'
'\.elc$' # compiled elisp
( run in 1.690 second using v1.01-cache-2.11-cpan-39bf76dae61 )