updated git and svn scripts
[xrzperl.git] / strip_lines_between
blob33cc0113b68685030ebb6e0e9bda314930ad2180
1 #!/usr/bin/perl -w
2 # $Id$
3 use strict;
4 require v5.10.0;
5 our $VERSION = 'v0.1';
7 BEGIN
9 my $PROGRAM_DIR = $0;
10 $PROGRAM_DIR =~ s/[^\/\\]+$//;
11 $PROGRAM_DIR = "./" unless($PROGRAM_DIR);
12 unshift @INC,
13 map "$PROGRAM_DIR$_",qw{modules lib ../modules ..lib};
16 my %OPTS;
17 my @OPTIONS = qw/help|h|? version|ver edit-me manual|man/;
19 if(@ARGV)
21 require Getopt::Long;
22 require MyPlace::Usage;
23 Getopt::Long::GetOptions(\%OPTS,@OPTIONS);
24 MyPlace::Usage::Process(\%OPTS,$VERSION);
26 else
28 require MyPlace::Usage;
29 MyPlace::Usage::PrintHelp();
32 my($start_exp,$end_exp,@files) = @ARGV;
33 die("Usage:$0 start_exp end_exp files...\n") unless(@files);
34 foreach my $org_file (@files) {
35 if(-f $org_file) {
36 my @org_data=();
37 my @new_data=();
38 my $modified=0;
39 if(open FI,"<",$org_file) {
40 @org_data = <FI>;
41 close FI;
42 my $between;
43 foreach(@org_data)
45 if($between)
47 $between=0 if(m/$end_exp/);
49 elsif(/$start_exp/)
51 $between = 1;
52 $modified = 1;
55 else {
56 push @new_data,$_;
59 if($modified) {
60 print STDERR "Backup $org_file ...\n";
61 system("cp","-av",$org_file,$org_file . ".org");
62 print STDERR "Modify $org_file ...\n";
63 if(open FO,">",$org_file)
65 print FO @new_data;
66 close FO;
68 else
70 print STDERR "$!\n";
71 next;
75 else {
76 print STDERR "$!\n";
77 next;
80 else {
81 print STDERR "File not accessible : $org_file\n";
87 __END__
89 =pod
91 =head1 NAME
93 strip_lines_between - strip lines from text files using regextp
95 =head1 SYNOPSIS
97 strip_lines_between start_exp end_exp file1 [file2 ...]
99 =head1 OPTIONS
101 =over 12
103 =item B<--version>
105 Print version infomation.
107 =item B<-h>,B<--help>
109 Print a brief help message and exits.
111 =item B<--manual>,B<--man>
113 View application manual
115 =item B<--edit-me>
117 Invoke 'editor' against the source
119 =back
121 =head1 DESCRIPTION
123 Strip lines between START_EXP and END_EXP from text files
125 =head1 CHANGELOG
127 2010-06-08 xiaoranzzz <xiaoranzzz@myplace.hell>
129 * file created.
131 =head1 AUTHOR
133 xiaoranzzz <xiaoranzzz@myplace.hell>
135 =cut