/[cvs]/nfo/perl/scripts/archiver/refactor/replace_cvs/replace.pl
ViewVC logotype

Contents of /nfo/perl/scripts/archiver/refactor/replace_cvs/replace.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Sat Feb 1 01:46:09 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
+ initial commit - moved here from joko/Scripts/replace/

1 #!/usr/bin/perl
2
3 ## -----------------------------------------------------------------------------------------
4 ## $Id: replace.pl,v 1.1 2002/10/17 04:45:45 joko Exp $
5 ## -----------------------------------------------------------------------------------------
6 ## $Log: replace.pl,v $
7 ## Revision 1.1 2002/10/17 04:45:45 joko
8 ## + new
9 ##
10 ##
11 ## -----------------------------------------------------------------------------------------
12
13 use strict;
14 use warnings;
15
16 use Carp;
17 use File::Find;
18 use Getopt::Long;
19
20 my $basedir;
21 my $pattern_substitution;
22 my $pattern_filename;
23 my $verbose;
24 my $dryrun;
25
26 GetOptions(
27 'basedir=s' => \$basedir,
28 'file-pattern=s' => \$pattern_substitution,
29 'substitution-pattern=s' => \$pattern_filename,
30 'dry-run=s' => \$dryrun,
31 #'interactive=s' => \$verbose,
32 'verbose=s' => \$verbose,
33 #'report=s' => \$verbose,
34 'usage' => \&usage,
35 'help' => \&usage,
36 );
37
38 sub usage {
39 print <<EOU;
40
41 replace.pl -- replaces contents in files by applying regular expression
42
43 --substitution-pattern: give regex-pattern for substitution (e.g. "s/world/earth/")
44 --file-pattern:
45 --basedir
46
47 EOU
48
49 }
50
51
52 my $pattern = shift;
53 croak("no pattern!") unless $pattern;
54
55 my $path = shift;
56 croak("no path!") unless $path;
57
58 my $pattern_file = '/CVS/Root';
59
60 exit;
61
62 sub replaceInFile {
63 my $filename = shift;
64 my $filename_bak = $filename . ".bak";
65 open(RH, $filename);
66 open(WH, '>' . $filename_bak);
67 while(<RH>) {
68 eval($pattern);
69 #print $_, "\n";
70 print WH $_;
71 }
72 close(WH);
73 close(RH);
74
75 unlink $filename;
76 rename $filename_bak, $filename;
77
78 }
79
80 sub wanted {
81 if ($File::Find::name =~ m/$pattern_file$/) {
82 print $File::Find::name, "\n";
83 replaceInFile($File::Find::name);
84 #exit;
85 }
86 }
87
88 sub main {
89 find(\&wanted, $path);
90 }
91
92 main();

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed