1 |
joko |
1.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 |
|
|
## ------------------------------------------------------------------------ |
8 |
|
|
|
9 |
|
|
|
10 |
|
|
=pod |
11 |
|
|
|
12 |
|
|
modifier.pl - modify things (files) using regular expressions |
13 |
|
|
|
14 |
|
|
- cat <file.txt> | ./modifier.pl --regex=s/:pserver:/:ext:/ |
15 |
|
|
modifies content piped to it applying the regular expression given (on unix) |
16 |
|
|
|
17 |
|
|
- type <file.txt> | perl modifier.pl --regex="s/main/Hello World!/g" |
18 |
|
|
modifies content piped to it applying the regular expression given (on win32) |
19 |
|
|
|
20 |
|
|
=cut |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
use strict; |
24 |
|
|
use warnings; |
25 |
|
|
|
26 |
|
|
BEGIN { |
27 |
|
|
use FindBin qw($Bin); |
28 |
|
|
#require "$Bin/use_libs.pl"; |
29 |
|
|
#use org::netfrag::preambel; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
use lib qw( ../../../libs ../libs ../etc ); |
33 |
|
|
|
34 |
|
|
use Data::Dumper; |
35 |
|
|
use Getopt::Easy; |
36 |
|
|
|
37 |
|
|
# ---------------------------------------- |
38 |
|
|
package main; |
39 |
|
|
|
40 |
|
|
my $settings; |
41 |
|
|
|
42 |
|
|
sub main { |
43 |
|
|
|
44 |
|
|
my $defaults = { |
45 |
|
|
options => { |
46 |
|
|
'in-type' => 'content', |
47 |
|
|
#'in-type' => 'pathlist', |
48 |
|
|
#'regex' => '.*', |
49 |
|
|
}, |
50 |
|
|
#args => [qw( . )], |
51 |
|
|
}; |
52 |
|
|
|
53 |
|
|
my $optReader = Getopt::Easy->new(); |
54 |
|
|
$optReader->merge_defaults($defaults); |
55 |
|
|
$optReader->merge_cli_arguments(); |
56 |
|
|
$settings = $optReader->getOptions(); |
57 |
|
|
|
58 |
|
|
if (!$settings->{options}->{regex}) { |
59 |
|
|
die("Please specify regular expression to apply to " . $settings->{options}->{'in-type'}); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
#print Dumper($settings); exit; |
63 |
|
|
#print Dumper($settings); |
64 |
|
|
replace(); |
65 |
|
|
|
66 |
|
|
#find(\&wanted, $settings->{args}->[0]); |
67 |
|
|
#my $where = $settings->{args}->[0]; |
68 |
|
|
#find(\&wanted, $where); |
69 |
|
|
|
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
sub replace { |
73 |
|
|
|
74 |
|
|
if ($settings->{options}->{'in-type'} eq 'content') { |
75 |
|
|
my @buffer; |
76 |
|
|
my $pattern = $settings->{options}->{regex}; |
77 |
|
|
while (<STDIN>) { |
78 |
|
|
chomp; |
79 |
|
|
eval($pattern); |
80 |
|
|
print; |
81 |
|
|
print "\n"; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
} elsif ($settings->{options}->{'in-type'} eq 'pathlist') { |
85 |
|
|
die("not implemented yet!"); |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
} |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
main(); |
92 |
|
|
|
93 |
|
|
1; |
94 |
|
|
__END__ |