1 |
#!/usr/bin/perl |
2 |
|
3 |
## ------------------------------------------------------------------------ |
4 |
## $Id: finder.pl,v 1.1 2003/02/01 01:38:35 joko Exp $ |
5 |
## ------------------------------------------------------------------------ |
6 |
## $Log: finder.pl,v $ |
7 |
## Revision 1.1 2003/02/01 01:38:35 joko |
8 |
## + initial commit - partly refactored from replace_cvs.pl |
9 |
## |
10 |
## ------------------------------------------------------------------------ |
11 |
|
12 |
|
13 |
=pod |
14 |
|
15 |
finder.pl - find things (files) and print their names on STDOUT |
16 |
|
17 |
- finder.pl |
18 |
finds all files/directories in current path |
19 |
|
20 |
- finder.pl . |
21 |
finds all files/directories in current path (again) |
22 |
|
23 |
- finder.pl --regex=test |
24 |
finds all files/directories matching 'regex' in current path |
25 |
|
26 |
- finder.pl --regex=/CVS/Root$ /tmp/cvsroot |
27 |
finds all files/directories matching 'regex' in path '/tmp/cvsroot' and below (recursively) |
28 |
|
29 |
=cut |
30 |
|
31 |
|
32 |
use strict; |
33 |
use warnings; |
34 |
|
35 |
BEGIN { |
36 |
use FindBin qw($Bin); |
37 |
#require "$Bin/use_libs.pl"; |
38 |
#use org::netfrag::preambel; |
39 |
} |
40 |
|
41 |
use lib qw( ../../../libs ../libs ../etc ); |
42 |
|
43 |
use Data::Dumper; |
44 |
use File::Find; |
45 |
use Getopt::Easy; |
46 |
|
47 |
|
48 |
# ---------------------------------------- |
49 |
package main; |
50 |
|
51 |
my $settings; |
52 |
|
53 |
sub wanted { |
54 |
my $pattern = $settings->{options}->{regex}; |
55 |
#print "pattern: $pattern", "\n"; |
56 |
if ($File::Find::name =~ m/$pattern/) { |
57 |
print $File::Find::name, "\n"; |
58 |
#replaceInFile($File::Find::name); |
59 |
#exit; |
60 |
} |
61 |
} |
62 |
|
63 |
sub main { |
64 |
|
65 |
my $defaults = { |
66 |
options => { |
67 |
'recursive' => 0, |
68 |
'regex' => '.*', |
69 |
}, |
70 |
args => [qw( . )], |
71 |
}; |
72 |
|
73 |
my $optReader = Getopt::Easy->new(); |
74 |
$optReader->merge_defaults($defaults); |
75 |
$optReader->merge_cli_arguments(); |
76 |
$settings = $optReader->getOptions(); |
77 |
|
78 |
#print Dumper($settings); exit; |
79 |
|
80 |
#find(\&wanted, $settings->{args}->[0]); |
81 |
my $where = $settings->{args}->[0]; |
82 |
find(\&wanted, $where); |
83 |
|
84 |
} |
85 |
|
86 |
main(); |
87 |
|
88 |
1; |
89 |
__END__ |