#!/usr/bin/perl -w use strict; my $regexp = $ARGV[0] || die "\nREQUIRES COMMAND-LINE ARGUMENT\n"; my $dir; if (defined($ARGV[1])) {$dir = $ARGV[1]} else {$dir = `pwd`} chomp $dir; print "\"$regexp\" in $dir/*.pl:\n"; my (%N_index, @files); opendir(DIR, $dir) || die "can't open $dir"; @files = readdir(DIR); closedir(DIR); foreach my $pl (@files) { if ($pl =~ /\.pl$/) { my $content; open (PL, "<$dir/$pl") || die "can't open $dir/$pl"; #while (<PL>) { $content = do {local $/; <PL>}; #} that was the deleted "while loop" close (PL); my $N; if ($content =~ /$regexp/) { $_=$content; $N =()= /$regexp/g; $N_index{$pl}=$N; } } } my @rank = sort {$N_index{$b} <=> $N_index{$a}} keys %N_index; foreach (@rank) {print "\t$N_index{$_} -- $_\n";}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regexp for directory
by toolic (Bishop) on Mar 17, 2008 at 15:28 UTC | |
by my_nihilist (Sexton) on Mar 17, 2008 at 16:36 UTC | |
by halfcountplus (Hermit) on Mar 17, 2008 at 19:55 UTC | |
by Fletch (Bishop) on Mar 17, 2008 at 21:13 UTC | |
by halfcountplus (Hermit) on Mar 18, 2008 at 13:28 UTC |