3 print "\nModifying the '.t' files...\n\n";
8 ## Change the below line to the folder you want to process
9 $DirName = "/perl/scripts/t";
15 opendir(DIR, $DirName);
18 foreach $DirItem(@Dirs)
20 $DirItem = $DirName."/".$DirItem;
21 push @DirNames, $DirItem; # All items under $DirName folder is copied into an array.
24 foreach $FileName(@DirNames)
27 { # If an item is a folder, then open it further.
29 opendir(SUBDIR, $FileName);
30 @SubDirs = readdir(SUBDIR);
33 foreach $SubFileName(@SubDirs)
37 &Process_File($SubFileName); # If file, process it.
41 $SubFileName = $FileName."/".$SubFileName;
42 push @DirNames, $SubFileName; # If sub-folder, push it into the array.
50 &Process_File($FileName); # If file, process it.
57 print "\n\n\nTotal number of files present = $FilesTotal\n";
58 print "Total number of '.t' files read = $FilesRead\n";
59 print "Total number of '.t' files modified = $FilesModified\n\n";
67 local($FileToProcess) = @_; # File name.
70 if(!(-w $FileToProcess)) {
71 # If the file is a read-only file, then change its mode to read-write.
72 chmod(0777, $FileToProcess);
76 ## If the value of $FileToProcess is '/perl/scripts/t/pragma/warnings.t', then
77 ## $dir = '/perl/scripts/t/pragma/'
80 $dir = dirname($FileToProcess); # Get the folder name
81 $base = basename($FileToProcess); # Get the base name
82 ($base, $dir, $ext) = fileparse($FileToProcess, '\..*'); # Get the extension of the file passed.
85 # Do the processing only if the file has '.t' extension.
88 open(FH, "+< $FileToProcess") or die "Unable to open the file, $FileToProcess for reading and writing.\n";
89 @ARRAY = <FH>; # Get the contents of the file into an array.
91 foreach $Line(@ARRAY) # Get each line of the file.
93 if($Line =~ m/\@INC = /)
94 { # If the line contains the string (@INC = ), then replace it
96 # Replace "@INC = " with "unshift @INC, "
97 $Line =~ s/\@INC = /unshift \@INC, /;
102 if($Line =~ m/push \@INC, /)
103 { # If the line contains the string (push @INC, ), then replace it
105 # Replace "push @INC, " with "unshift @INC, "
106 $Line =~ s/push \@INC, /unshift \@INC, /;
112 seek(FH, 0, 0); # Seek to the beginning.
113 print FH @ARRAY; # Write the changed array into the file.
114 close FH; # close the file.
116 $FilesRead++; # One more file read.
119 print "Modified the file, $FileToProcess\n";
122 $FilesModified++; # One more file modified.
126 $FilesTotal++; # One more file present.