#!/pro/bin/perl use strict; use warnings; use Getopt::Long qw(:config bundling nopermute passthrough); my $opt_l = 0; my $opt_w = 0; GetOptions ( "w|word!" => \$opt_w, "l|list!" => \$opt_l, ) or die "usage: metagrep [-w] [-l] 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 = ($mcpath, "$mcpath/dist/U"); 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}++; }, @dir); print STDERR "<$pat>\n"; my %seen; 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"; $File::Find::dir =~ m{^(?:$cwd/)?dist-3} and return; open my $f, "<$_" or die "$File::Find::name: $!\n"; my $fnm = $File::Find::name; $fnm =~ s{^$cwd/}{}; for (grep /$pat/, <$f>) { if ($opt_l) { $seen{$fnm}++ or print "$fnm\n"; next; } print "$fnm:$_"; } }, @dir);