#!/pro/bin/perl use strict; use warnings; use Getopt::Long qw(:config bundling nopermute passthrough); my $opt_w = 0; GetOptions ( "-w" => \$opt_w, ) or die "usage: metagrep [-w] pattern\n"; use Cwd qw(getcwd abs_path); use File::Find; my $pat = shift or die "usage: metagrep pattern\n"; $opt_w and $pat = "\\b$pat\\b"; $pat = qr/$pat/i; my $cwd = getcwd; my $mcpath = abs_path "/pro/3gl/CPAN/metaconfig" or die "cannot cd metaconfig\n"; my $onmeta = $cwd =~ m{CPAN/meta[^/]+$} ? 1 : 0; my %dir; # I don't want a file for which any path component symlinks find (sub { -l and return; -d and $dir{$File::Find::name}++; }, $mcpath); print STDERR "<$pat>\n"; find (sub { -l and return; -f or return; m/\.U$/ or return; exists $dir{$File::Find::dir} or return; #print STDERR "$File::Find::dir - $_\n"; open my $f, "<$_" or die "$File::Find::name: $!\n"; my $fnm = $File::Find::name; $fnm =~ s{^$cwd/}{}; print map { "$fnm:$_" } grep /$pat/, <$f>; }, $mcpath);