lib/App/SeismicUnixGui/developer/code/sunix/replacelines.pl untested

filter: Statementstmt 0.0% 0 / 59 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 1 Podpod n/a totaltotal 0.0% 0 / 97 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
CRAP 2.0
1 use Moose;
2 our $VERSION = '0.0.1';
3  
4 my $MAIN_DIR = '/usr/local/pl/L_SU/specs';
5 my ( @INBOUND, @SUBDIR );
6 my @directories;
7 my @line;
8 my $number_of_lines;
9  
10 # print("MAIN_DIR= $MAIN_DIR\n");
11  
12 # Contents of main directory
13 opendir( DIR, $MAIN_DIR ) or die $!;
14 my @directory_list = readdir(DIR);
15 close(DIR);
16  
17 # print @directory_list;
18  
19 foreach my $thing (@directory_list) {
20  
21 if ( $thing eq '.'
22 or $thing eq '..'
23 or $thing =~ /.pm/ ) {
24  
25 next;
26  
27 } else {
28 push @directories, $MAIN_DIR . '/' . $thing;
29  
30 # print("DIR= $thing\n");
31 }
32 }
33  
34 # Listing within each subdirectory
35 foreach my $subdir (@directories) {
36 my @inbound;
37 print("\nWorking inside sub-directory: $subdir\n");
38  
39 opendir( DIR, $subdir ) or die $!;
40 my @file_list = readdir(DIR);
41 close(DIR);
42  
43 foreach my $file (@file_list) {
44  
45 if ( $file eq '.' or $file eq '..' ) {
46 next;
47  
48 } else {
49 push @inbound, $subdir . '/' . $file;
50  
51 print("file= $file\n");
52 }
53 }
54  
55 # Working with individual files in each subdirectory
56 foreach my $inbound_prog_spec (@inbound) {
57 my $i;
58 open( FH, $inbound_prog_spec ) or die("File $inbound_prog_spec not found");
59 print("opening up $inbound_prog_spec \n");
60  
61 $line[0] = <FH>;
62  
63 # print("line0= $line[0]\n");
64 $i = 1;
65  
66 while ( my $String = <FH> ) {
67 $line[$i] = $String;
68  
69 #my $other_words2find = '_has_infile';
70 my $other_words2find = '_has_pipe_in';
71  
72 # my $words2find = '_has_pipe_in';
73 # my $words2find = '_has_pipe_out';
74 my $words2find = '_has_outpar';
75  
76 if ( $line[$i] =~ /$words2find/
77 and ( $line[ ( $i - 1 ) ] =~ /$other_words2find/ ) ) {
78  
79 print "found $line[($i-1)] and $line[$i]\n";
80  
81 # exchange lines
82 my $temp = $line[ ( $i - 1 ) ];
83 $line[ ( $i - 1 ) ] = $line[$i];
84 $line[$i] = $temp;
85 print "reversed: $line[($i-1)] and $line[$i]\n";
86  
87 } # check words
88  
89 $i++; # track lines
90 } # inside a file
91 close(FH);
92  
93 # write out the corrected file
94 $number_of_lines = $i;
95 print("number of lines= $i\n");
96 open( OUT, ">$inbound_prog_spec" ) or die("File $inbound_prog_spec not found");
97 print("writing our $inbound_prog_spec\n");
98 for ( my $i = 0; $i < $number_of_lines; $i++ ) {
99 print OUT $line[$i];
100 }
101 close(OUT);
102 } # for each file
103  
104 } # within each subdirectory
105