| 1 | |||
| 2 | =head2 SYNOPSIS | ||
| 3 | |||
| 4 | PERL PROGRAM NAME: change_a_line_everywhere | ||
| 5 | |||
| 6 | AUTHOR: | ||
| 7 | |||
| 8 | DATE: V 0.1 Jun 15 2022 | ||
| 9 | |||
| 10 | DESCRIPTION: replace Perl directory | ||
| 11 | structure within all files | ||
| 12 | |||
| 13 | Version: 0.1 | ||
| 14 | 0.2 use search_directories.pm instead | ||
| 15 | of L_SU_global_variables.pm | ||
| 16 | 0.3 use dirs.pm instead of search_directories.pm | ||
| 17 | 0.4 update PARENT_DIR and CHILD_DIR assignments to conform | ||
| 18 | with the new dirs.pm (V0.3) 10.25.23 | ||
| 19 | |||
| 20 | =head2 USE | ||
| 21 | |||
| 22 | =head3 NOTES | ||
| 23 | |||
| 24 | The is a grandparent:parent:child relationship for | ||
| 25 | two of the sets of directories | ||
| 26 | |||
| 27 | but only a grandparent:parent relationship for the | ||
| 28 | remaining third directory set. | ||
| 29 | |||
| 30 | Based on change_a_line V0.1 | ||
| 31 | |||
| 32 | =head4 Examples | ||
| 33 | |||
| 34 | =head2 SYNOPSIS | ||
| 35 | |||
| 36 | Look at every file with a .pm and .pl extension | ||
| 37 | Requires looking at all files within the | ||
| 38 | following categories (See search_directories) | ||
| 39 | SU, GEN, SPECS, GUI, TOOLS | ||
| 40 | |||
| 41 | 1. for each of 4 categories get | ||
| 42 | CATEGORY[ABS_PATHs][FILmy $line2find_use = '\s*use\s';E_NAMEs] = 'full path and file name' | ||
| 43 | (from search_directories) | ||
| 44 | |||
| 45 | 2. Search every file for the lines of interest (loi) | ||
| 46 | CATEGORY_lines_of_interest[ABS_PATHs][FILE_NAMES] = array_ref | ||
| 47 | e.g.: lines 1 and 2 | ||
| 48 | slurp file | ||
| 49 | test every line | ||
| 50 | write loi to array | ||
| 51 | |||
| 52 | 3. For each CATEGORY[ABS_PATHs][FILE_NAMEs],look at loi | ||
| 53 | slurp file again | ||
| 54 | |||
| 55 | Review conditions | ||
| 56 | Replace the line with proper hierarchy | ||
| 57 | relative_path::file_name | ||
| 58 | Add other special lines | ||
| 59 | |||
| 60 | replace old with new file | ||
| 61 | |||
| 62 | =head2 CHANGES and their DATES | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | use Moose; | ||
| 67 | our $VERSION = '0.3.0'; | ||
| 68 | |||
| 69 | use aliased 'App::SeismicUnixGui::misc::manage_dirs_by'; | ||
| 70 | use aliased 'App::SeismicUnixGui::misc::manage_files_by2'; | ||
| 71 | use aliased 'App::SeismicUnixGui::misc::dirs'; | ||
| 72 | |||
| 73 | my $manage_dirs_by = manage_dirs_by->new(); | ||
| 74 | my $manage_files_by2 = manage_files_by2->new(); | ||
| 75 | my $dirs = dirs->new(); | ||
| 76 | |||
| 77 | =head2 Important definitions | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | #type1 | ||
| 82 | #my $line2find = '^package\s\w+\;'; | ||
| 83 | |||
| 84 | #type2 | ||
| 85 | #my $line2find = '^use\sApp::SeismicUnixGui(.+\w)+::(?!SeismicUnix)'; | ||
| 86 | |||
| 87 | #type 3 | ||
| 88 | #my $line2find = '=\snew\s\w+'; | ||
| 89 | |||
| 90 | #type 4 | ||
| 91 | #my $line2find = 'use\saliased\s\'App'; | ||
| 92 | |||
| 93 | #type 5 | ||
| 94 | #my $line2find = 'our\s\$VERSION'; | ||
| 95 | |||
| 96 | #type 6 | ||
| 97 | #my $line2find = 'use\ Moose;'; | ||
| 98 | |||
| 99 | #type 7 | ||
| 100 | my $line2find = 'AUTHOR:'; | ||
| 101 | |||
| 102 | =head2 Important definitions | ||
| 103 | |||
| 104 | of directory structure. | ||
| 105 | Local development! | ||
| 106 | |||
| 107 | =cut | ||
| 108 | |||
| 109 | my $SeismicUnixGui = 'App-SeismicUnixGui/lib/App/SeismicUnixGui'; | ||
| 110 | my $PL_DIR = '/usr/local/pl'; | ||
| 111 | my $GRANDPARENT_DIR = $PL_DIR . '/' . $SeismicUnixGui; | ||
| 112 | |||
| 113 | =head2 privately shared hash | ||
| 114 | |||
| 115 | =cut | ||
| 116 | |||
| 117 | my $change_a_line = { | ||
| 118 | _child_directory_su_number_of => '', | ||
| 119 | _file_name => '', | ||
| 120 | _line_of_interest_aref => '', | ||
| 121 | _parent_directory_su_number_of => '', | ||
| 122 | _pathNfile_aref => '', | ||
| 123 | }; | ||
| 124 | |||
| 125 | =head2 Get all the files and their paths | ||
| 126 | |||
| 127 | from the SU category | ||
| 128 | |||
| 129 | =cut | ||
| 130 | |||
| 131 | #$dirs->set_CHILD_DIR_type('SU'); | ||
| 132 | #$dirs->set_PARENT_DIR_type('SU'); | ||
| 133 | #$dirs->set_GRANDPARENT_DIR($GRANDPARENT_DIR); | ||
| 134 | #my ( $su_pathNfile_aref, $su_dimension_aref ) = $dirs->get_pathNfile2search(); | ||
| 135 | |||
| 136 | =head2 search for lines of interest | ||
| 137 | |||
| 138 | in SU-type files and replace them | ||
| 139 | |||
| 140 | =cut | ||
| 141 | |||
| 142 | #my @dimension_su = @$su_dimension_aref; | ||
| 143 | #my $parent_directory_su_number_of = $dimension_su[0]; | ||
| 144 | #my $child_directory_su_number_of = $dimension_su[1]; | ||
| 145 | |||
| 146 | #print("parent_directory_su_number_of=$parent_directory_su_number_of\n"); | ||
| 147 | #print("child_directory_su_number_of=$child_directory_su_number_of\n"); | ||
| 148 | |||
| 149 | #my @su_pathNfile = @$su_pathNfile_aref; | ||
| 150 | # | ||
| 151 | #_set_parent_directory_number_of($parent_directory_su_number_of); | ||
| 152 | #_set_child_directory_number_of($child_directory_su_number_of); | ||
| 153 | #_set_pathNfile_aref($su_pathNfile_aref); | ||
| 154 | #my $su_aref = _get_line_of_interest_aref(); | ||
| 155 | #my @line_of_interest_su_aref = @$su_aref; | ||
| 156 | #_set_line_of_interest_aref($su_aref); | ||
| 157 | |||
| 158 | #_set_replacement_type5(); | ||
| 159 | #_set_replacement_type6(); | ||
| 160 | #_set_replacement_type7(); | ||
| 161 | |||
| 162 | =head2 Get all the files and their full paths | ||
| 163 | |||
| 164 | from the GEN category and replace them( | ||
| 165 | |||
| 166 | =cut | ||
| 167 | |||
| 168 | $dirs->set_CHILD_DIR_type('GEN'); | ||
| 169 | $dirs->set_PARENT_DIR_type('GEN'); | ||
| 170 | $dirs->set_GRANDPARENT_DIR($GRANDPARENT_DIR); | ||
| 171 | my ( $gen_pathNfile_aref, $gen_dimension_aref ) = | ||
| 172 | $dirs->get_pathNfile2search(); | ||
| 173 | |||
| 174 | =head2 search for lines of interest | ||
| 175 | |||
| 176 | in GEN-type files and replace them | ||
| 177 | |||
| 178 | =cut | ||
| 179 | |||
| 180 | my @dimension_gen = @$gen_dimension_aref; | ||
| 181 | my $parent_directory_gen_number_of = $dimension_gen[0]; | ||
| 182 | my $child_directory_gen_number_of = $dimension_gen[1]; | ||
| 183 | |||
| 184 | print("parent_directory_gen_number_of=$parent_directory_gen_number_of\n"); | ||
| 185 | print("child_directory_gen_number_of=$child_directory_gen_number_of\n"); | ||
| 186 | |||
| 187 | #my @gen_pathNfile = @$gen_pathNfile_aref; | ||
| 188 | ## | ||
| 189 | ##$parent_directory_gen_number_of = 1; | ||
| 190 | ##$child_directory_gen_number_of = 1; | ||
| 191 | #_set_parent_directory_number_of($parent_directory_gen_number_of); | ||
| 192 | #_set_child_directory_number_of($child_directory_gen_number_of); | ||
| 193 | #_set_pathNfile_aref($gen_pathNfile_aref); | ||
| 194 | #my $gen_aref = _get_line_of_interest_aref(); | ||
| 195 | #my @line_of_interest_gen_aref = @$gen_aref; | ||
| 196 | #_set_line_of_interest_aref($gen_aref); | ||
| 197 | # | ||
| 198 | #_set_replacement_type5(); | ||
| 199 | #_set_replacement_type6(); | ||
| 200 | #set_replacement_type7(); | ||
| 201 | |||
| 202 | =head2 Get all the files and their full paths | ||
| 203 | |||
| 204 | from the SPECS category | ||
| 205 | |||
| 206 | =cut | ||
| 207 | |||
| 208 | #$dirs->set_CHILD_DIR_type('SPECS'); | ||
| 209 | #$dirs->set_PARENT_DIR_type('SPECS'); | ||
| 210 | #$dirs->set_GRANDPARENT_DIR($GRANDPARENT_DIR); | ||
| 211 | #my ( $specs_pathNfile_aref, $specs_dimension_aref ) = | ||
| 212 | # $dirs->get_pathNfile2search(); | ||
| 213 | |||
| 214 | =head2 search for lines of interest | ||
| 215 | |||
| 216 | in SPECS-type files and replace them | ||
| 217 | |||
| 218 | =cut | ||
| 219 | |||
| 220 | #my @dimension_specs = @$specs_dimension_aref; | ||
| 221 | #my $parent_directory_specs_number_of = $dimension_specs[0]; | ||
| 222 | #my $child_directory_specs_number_of = $dimension_specs[1]; | ||
| 223 | # | ||
| 224 | #print("parent_directory_specs_number_of=$parent_directory_specs_number_of\n"); | ||
| 225 | #print("child_directory_specs_number_of=$child_directory_specs_number_of\n"); | ||
| 226 | # | ||
| 227 | #my @specs_pathNfile = @$specs_pathNfile_aref; | ||
| 228 | #_set_parent_directory_number_of($parent_directory_specs_number_of); | ||
| 229 | #_set_child_directory_number_of($child_directory_specs_number_of); | ||
| 230 | #_set_pathNfile_aref($specs_pathNfile_aref); | ||
| 231 | #my $specs_aref = _get_line_of_interest_aref(); | ||
| 232 | #my @line_of_interest_specs_aref = @$specs_aref; | ||
| 233 | #_set_line_of_interest_aref($specs_aref); | ||
| 234 | # | ||
| 235 | #_set_replacement_type5(); | ||
| 236 | #_set_replacement_type6(); | ||
| 237 | |||
| 238 | =head2 Get all the files and their full paths | ||
| 239 | |||
| 240 | from the GUI category | ||
| 241 | |||
| 242 | =cut | ||
| 243 | |||
| 244 | #$dirs->set_CHILD_DIR_type('GUI'); | ||
| 245 | #$dirs->set_PARENT_DIR_type('GUI'); | ||
| 246 | #$dirs->set_GRANDPARENT_DIR($GRANDPARENT_DIR); | ||
| 247 | #my ( $gui_pathNfile_aref, $gui_dimension_aref ) = | ||
| 248 | # $dirs->get_pathNfile2search(); | ||
| 249 | |||
| 250 | =head2 search for lines of interest | ||
| 251 | |||
| 252 | in GUI-type files and replace them | ||
| 253 | |||
| 254 | =cut | ||
| 255 | |||
| 256 | #my @dimension_gui = @$gui_dimension_aref; | ||
| 257 | #my $parent_directory_gui_number_of = $dimension_gui[0]; | ||
| 258 | #my $child_directory_gui_number_of = $dimension_gui[1]; | ||
| 259 | # | ||
| 260 | #print("parent_directory_gui_number_of=$parent_directory_gui_number_of\n"); | ||
| 261 | #print("child_directory_gui_number_of=$child_directory_gui_number_of\n"); | ||
| 262 | # | ||
| 263 | #_set_parent_directory_number_of($parent_directory_gui_number_of); | ||
| 264 | #_set_child_directory_number_of($child_directory_gui_number_of); | ||
| 265 | #_set_pathNfile_aref($gui_pathNfile_aref); | ||
| 266 | #my $gui_aref = _get_line_of_interest_aref(); | ||
| 267 | #my @line_of_interest_gui_aref =@$gui_aref; | ||
| 268 | #_set_line_of_interest_aref($gui_aref); | ||
| 269 | #_set_replacement_type5(); | ||
| 270 | #_set_replacement_type6(); | ||
| 271 | |||
| 272 | =head2 Get all the files and their full paths | ||
| 273 | |||
| 274 | from the TOOLS category | ||
| 275 | |||
| 276 | =cut | ||
| 277 | |||
| 278 | #$dirs->set_CHILD_DIR_type('TOOLS'); | ||
| 279 | #$dirs->set_PARENT_DIR_type('TOOLS'); | ||
| 280 | #$dirs->set_GRANDPARENT_DIR($GRANDPARENT_DIR); | ||
| 281 | #my ( $tools_pathNfile_aref, $tools_dimension_aref ) = | ||
| 282 | # $dirs->get_pathNfile2search(); | ||
| 283 | |||
| 284 | =head2 search for lines of interest | ||
| 285 | |||
| 286 | in TOOLS-type files and replace them | ||
| 287 | |||
| 288 | =cut | ||
| 289 | |||
| 290 | #my @dimension_tools = @$tools_dimension_aref; | ||
| 291 | #my $parent_directory_tools_number_of = $dimension_tools[0]; | ||
| 292 | #my $child_directory_tools_number_of = $dimension_tools[1]; | ||
| 293 | # | ||
| 294 | #print("parent_directory_tools_number_of=$parent_directory_tools_number_of\n"); | ||
| 295 | #print("child_directory_tools_number_of=$child_directory_tools_number_of\n"); | ||
| 296 | # | ||
| 297 | #_set_parent_directory_number_of($parent_directory_tools_number_of); | ||
| 298 | #_set_child_directory_number_of($child_directory_tools_number_of); | ||
| 299 | #_set_pathNfile_aref($tools_pathNfile_aref); | ||
| 300 | #my $tools_aref = _get_line_of_interest_aref(); | ||
| 301 | #my @line_of_interest_tools_aref =@$tools_aref; | ||
| 302 | #_set_line_of_interest_aref($tools_aref); | ||
| 303 | #_set_replacement_type5(); | ||
| 304 | #_set_replacement_type6(); | ||
| 305 | |||
| 306 | =head2 _get_line_of_interest_aref | ||
| 307 | |||
| 308 | =cut | ||
| 309 | |||
| 310 | sub _get_line_of_interest_aref { | ||
| 311 | |||
| 312 | my ($self) = @_; | ||
| 313 | |||
| 314 | my $child_directory_number_of = $change_a_line->{_child_directory_number_of}; | ||
| 315 | my $parent_directory_number_of = $change_a_line->{_parent_directory_number_of}; | ||
| 316 | my @pathNfile = @{ $change_a_line->{_pathNfile_aref} }; | ||
| 317 | |||
| 318 | my @line_of_interest_aref; | ||
| 319 | |||
| 320 | for ( my $parent = 0 ; $parent < $parent_directory_number_of ; $parent++ ) { | ||
| 321 | for ( my $child = 0 ; $child < $child_directory_number_of ; $child++ ) { | ||
| 322 | |||
| 323 | # print("starting inner count=$count; parent=$parent\n"); | ||
| 324 | my @pathNfile_list = @{ $pathNfile[$parent][$child] }; | ||
| 325 | my $pathNfile_list_length = scalar @pathNfile_list; | ||
| 326 | # print("0. pathNfile_list_length=$pathNfile_list_length\n"); | ||
| 327 | |||
| 328 | for ( | ||
| 329 | my $i = 0, my $count_idx = 0 ; | ||
| 330 | $i < $pathNfile_list_length ; | ||
| 331 | $i++, $count_idx++ | ||
| 332 | ) | ||
| 333 | { | ||
| 334 | |||
| 335 | my @line_of_interest4file; | ||
| 336 | |||
| 337 | # slurp every file | ||
| 338 | $manage_files_by2->set_pathNfile( $pathNfile_list[$i] ); | ||
| 339 | my $slurp_ref = | ||
| 340 | manage_files_by2->get_whole( $pathNfile_list[$i] ); | ||
| 341 | my @slurp = @$slurp_ref; | ||
| 342 | my $length_of_slurp = scalar @slurp; | ||
| 343 | |||
| 344 | # print("\n1. _get_line_of_interest_aref\n"); | ||
| 345 | # print("1. total count index =$count_idx\n"); | ||
| 346 | # print ("1. parent=$parent;child=$child;number=$i;pathNfile:$pathNfile_list[$i]\n"); | ||
| 347 | # print ("1. length_of_slurp=$length_of_slurp\n"); | ||
| 348 | |||
| 349 | for ( my $j = 0 ; $j < $length_of_slurp ; $j++ ) { | ||
| 350 | |||
| 351 | # CASE within each *.pm file | ||
| 352 | my $string = $slurp[$j]; | ||
| 353 | chomp $string; # remove all newlines | ||
| 354 | |||
| 355 | if ( $string =~ m/$line2find/ ) { | ||
| 356 | |||
| 357 | push @line_of_interest4file, $j; | ||
| 358 | |||
| 359 | # my $prior2loi = $j - 1; | ||
| 360 | # | ||
| 361 | # print("\n2._get_line_of_interest_aref\n"); | ||
| 362 | # print("2.at loi=$j, string=$string; \n\tin $pathNfile_list[$i]\n"); | ||
| 363 | # print( | ||
| 364 | # "string prior2loi=$prior2loi is: $slurp[$prior2loi]\n" | ||
| 365 | # ); | ||
| 366 | |||
| 367 | } | ||
| 368 | } # lines in a file | ||
| 369 | |||
| 370 | $line_of_interest_aref[$parent][$child][$i] = | ||
| 371 | \@line_of_interest4file; | ||
| 372 | |||
| 373 | } #for files in a list | ||
| 374 | |||
| 375 | } # for each child directory | ||
| 376 | |||
| 377 | } #for each parent directory | ||
| 378 | |||
| 379 | my $result = \@line_of_interest_aref; | ||
| 380 | return ($result); | ||
| 381 | } | ||
| 382 | |||
| 383 | =head2 sub _set_child_directory_number_of | ||
| 384 | |||
| 385 | =cut | ||
| 386 | |||
| 387 | sub _set_child_directory_number_of { | ||
| 388 | |||
| 389 | my ($self) = @_; | ||
| 390 | |||
| 391 | $change_a_line->{_child_directory_number_of} = $self; | ||
| 392 | |||
| 393 | # print ("_set_child_directory_number_of=$self\n"); | ||
| 394 | |||
| 395 | return (); | ||
| 396 | } | ||
| 397 | |||
| 398 | =head2 sub _set_line_of_interest_aref | ||
| 399 | |||
| 400 | =cut | ||
| 401 | |||
| 402 | sub _set_line_of_interest_aref { | ||
| 403 | |||
| 404 | my ($self) = @_; | ||
| 405 | |||
| 406 | $change_a_line->{_line_of_interest_aref} = $self; | ||
| 407 | |||
| 408 | # print ("_set_line_of_interest_aref=$self\n"); | ||
| 409 | return (); | ||
| 410 | } | ||
| 411 | |||
| 412 | =head2 sub _set_parent_directory_number_of | ||
| 413 | |||
| 414 | =cut | ||
| 415 | |||
| 416 | sub _set_parent_directory_number_of { | ||
| 417 | |||
| 418 | my ($self) = @_; | ||
| 419 | |||
| 420 | $change_a_line->{_parent_directory_number_of} = $self; | ||
| 421 | |||
| 422 | # print ("_set_parent_directory_number_of=$self\n"); | ||
| 423 | return (); | ||
| 424 | } | ||
| 425 | |||
| 426 | =head2 sub _set_pathNfile_aref | ||
| 427 | |||
| 428 | =cut | ||
| 429 | |||
| 430 | sub _set_pathNfile_aref { | ||
| 431 | my ($self) = @_; | ||
| 432 | |||
| 433 | $change_a_line->{_pathNfile_aref} = $self; | ||
| 434 | return (); | ||
| 435 | } | ||
| 436 | |||
| 437 | #=head2 set_replacement_type1 | ||
| 438 | # | ||
| 439 | #replace line of interest | ||
| 440 | # | ||
| 441 | #=cut | ||
| 442 | # | ||
| 443 | #sub _set_replacement_type1 { | ||
| 444 | # | ||
| 445 | # my ($self) = @_; | ||
| 446 | # | ||
| 447 | # my $child_directory_number_of = | ||
| 448 | # $change_a_line->{_child_directory_number_of}; | ||
| 449 | # my $parent_directory_number_of = | ||
| 450 | # $change_a_line->{_parent_directory_number_of}; | ||
| 451 | # my @pathNfile = @{ $change_a_line->{_pathNfile_aref} }; | ||
| 452 | # my @line_of_interest_aref = @{ $change_a_line->{_line_of_interest_aref} }; | ||
| 453 | # | ||
| 454 | # for ( my $parent = 0 ; $parent < $parent_directory_number_of ; $parent++ ) { | ||
| 455 | # | ||
| 456 | # for ( my $child = 0 ; $child < $child_directory_number_of ; $child++ ) { | ||
| 457 | # | ||
| 458 | # my @pathNfile_list = @{ $pathNfile[$parent][$child] }; | ||
| 459 | # my $pathNfile_list_length = scalar @pathNfile_list; | ||
| 460 | # | ||
| 461 | # for ( my $i = 0 ; $i < $pathNfile_list_length ; $i++ ) { | ||
| 462 | # | ||
| 463 | # # slurp every file | ||
| 464 | # $manage_files_by2->set_pathNfile( $pathNfile_list[$i] ); | ||
| 465 | # my $slurp_ref = | ||
| 466 | # manage_files_by2->get_whole( $pathNfile_list[$i] ); | ||
| 467 | # my @slurp = @$slurp_ref; | ||
| 468 | # | ||
| 469 | # my @line_number = | ||
| 470 | # @{ $line_of_interest_aref[$parent][$child][$i] }; | ||
| 471 | # my $line_number_of = scalar @line_number; | ||
| 472 | # | ||
| 473 | # # print("child directory=$child\n"); | ||
| 474 | # # print $pathNfile_list[$i]." file number =$i\n"; | ||
| 475 | # # print("line_number_of=$line_number_of\n"); | ||
| 476 | # | ||
| 477 | # if ( $line_number_of > 0 ) { | ||
| 478 | # | ||
| 479 | # # print("line_number=@line_number\n"); | ||
| 480 | # # print("line_number_of=$line_number_of\n"); | ||
| 481 | # | ||
| 482 | # foreach my $line (@line_number) { | ||
| 483 | # | ||
| 484 | # chomp $slurp[$line]; | ||
| 485 | # my $path = $pathNfile_list[$i]; | ||
| 486 | # $path =~ | ||
| 487 | # s/\/usr\/local\/pl\/App-SeismicUnixGui\/lib\///; | ||
| 488 | # | ||
| 489 | # # substitute "/" with ":" | ||
| 490 | # $path =~ s/(\/)+/::/g; | ||
| 491 | # $path =~ s/.pm//g; | ||
| 492 | # $slurp[$line] = 'package' . ' ' . $path . ';'; | ||
| 493 | # print("hierarchical path =$slurp[$line]\n"); | ||
| 494 | # | ||
| 495 | # } | ||
| 496 | # | ||
| 497 | # print("Hit Enter to continue\n"); | ||
| 498 | # <STDIN>; | ||
| 499 | # | ||
| 500 | # open( OUT, ">$pathNfile_list[$i]" ) | ||
| 501 | # or die("File $pathNfile_list[$i] not found"); | ||
| 502 | # | ||
| 503 | # foreach my $text (@slurp) { | ||
| 504 | # print OUT $text . "\n"; # add \n!!!! | ||
| 505 | # # print("$text \n"); | ||
| 506 | # } | ||
| 507 | # | ||
| 508 | # close(OUT); | ||
| 509 | # | ||
| 510 | # } | ||
| 511 | # else { | ||
| 512 | # # print("\npathNfile_list=$pathNfile_list[$i]\n"); | ||
| 513 | # # print("main,no matching lines detected\n"); | ||
| 514 | # } | ||
| 515 | # | ||
| 516 | # } # for files in a list | ||
| 517 | # | ||
| 518 | # } # for each child directory | ||
| 519 | # | ||
| 520 | # } #for each parent directory | ||
| 521 | # | ||
| 522 | #} # sub replace line of interest | ||
| 523 | # | ||
| 524 | #=head2 set_replacement_type2 | ||
| 525 | # | ||
| 526 | #replace line of interest | ||
| 527 | # | ||
| 528 | #=cut | ||
| 529 | # | ||
| 530 | #sub _set_replacement_type2 { | ||
| 531 | # | ||
| 532 | # my ($self) = @_; | ||
| 533 | # | ||
| 534 | # my $child_directory_number_of = | ||
| 535 | # $change_a_line->{_child_directory_number_of}; | ||
| 536 | # my $parent_directory_number_of = | ||
| 537 | # $change_a_line->{_parent_directory_number_of}; | ||
| 538 | # my @pathNfile = @{ $change_a_line->{_pathNfile_aref} }; | ||
| 539 | # my @line_of_interest_aref = @{ $change_a_line->{_line_of_interest_aref} }; | ||
| 540 | # | ||
| 541 | # for ( my $parent = 0 ; $parent < $parent_directory_number_of ; $parent++ ) { | ||
| 542 | # | ||
| 543 | # for ( my $child = 0 ; $child < $child_directory_number_of ; $child++ ) { | ||
| 544 | # | ||
| 545 | # my @pathNfile_list = @{ $pathNfile[$parent][$child] }; | ||
| 546 | # my $pathNfile_list_length = scalar @pathNfile_list; | ||
| 547 | # | ||
| 548 | # for ( my $i = 0 ; $i < $pathNfile_list_length ; $i++ ) { | ||
| 549 | # | ||
| 550 | # # slurp every file | ||
| 551 | # $manage_files_by2->set_pathNfile( $pathNfile_list[$i] ); | ||
| 552 | # my $slurp_ref = | ||
| 553 | # manage_files_by2->get_whole( $pathNfile_list[$i] ); | ||
| 554 | # my @slurp = @$slurp_ref; | ||
| 555 | # | ||
| 556 | # my @line_number = | ||
| 557 | # @{ $line_of_interest_aref[$parent][$child][$i] }; | ||
| 558 | # my $line_number_of = scalar @line_number; | ||
| 559 | # | ||
| 560 | # if ( $line_number_of > 0 ) { | ||
| 561 | # | ||
| 562 | # foreach my $line (@line_number) { | ||
| 563 | # | ||
| 564 | # chomp $slurp[$line]; | ||
| 565 | # print $slurp[$line] . "\n"; | ||
| 566 | # | ||
| 567 | # if ( not( $slurp[$line] =~ m/\'/ ) ) | ||
| 568 | # { #skip version cases | ||
| 569 | # | ||
| 570 | # # substitute "use App ....;" with "use aliased 'App...';" | ||
| 571 | # $slurp[$line] =~ s/use\sApp/use aliased 'App/g; | ||
| 572 | # $slurp[$line] =~ s/;/\';/; | ||
| 573 | # print("new line =$slurp[$line]\n"); | ||
| 574 | # | ||
| 575 | # } | ||
| 576 | # | ||
| 577 | # } | ||
| 578 | # | ||
| 579 | # print("Hit Enter to continue\n"); | ||
| 580 | # <STDIN>; | ||
| 581 | # | ||
| 582 | # open( OUT, ">$pathNfile_list[$i]" ) | ||
| 583 | # or die("File $pathNfile_list[$i] not found"); | ||
| 584 | # | ||
| 585 | # foreach my $text (@slurp) { | ||
| 586 | # print OUT $text . "\n"; # add \n!!!! | ||
| 587 | # | ||
| 588 | # # print("$text \n"); | ||
| 589 | # } | ||
| 590 | # | ||
| 591 | # close(OUT); | ||
| 592 | # | ||
| 593 | # } | ||
| 594 | # else { | ||
| 595 | # # print("\npathNfile_list=$pathNfile_list[$i]\n"); | ||
| 596 | # # print("main,no matching lines detected\n"); | ||
| 597 | # } | ||
| 598 | # | ||
| 599 | # } # for files in a list | ||
| 600 | # | ||
| 601 | # } # for each child directory | ||
| 602 | # | ||
| 603 | # } #for each parent directory | ||
| 604 | # | ||
| 605 | #} # sub replace line of interest | ||
| 606 | # | ||
| 607 | #=head2 set_replacement_type3 | ||
| 608 | # | ||
| 609 | #replace line of interest | ||
| 610 | # | ||
| 611 | #=cut | ||
| 612 | # | ||
| 613 | #sub _set_replacement_type3 { | ||
| 614 | # | ||
| 615 | # my ($self) = @_; | ||
| 616 | # | ||
| 617 | # my $child_directory_number_of = | ||
| 618 | # $change_a_line->{_child_directory_number_of}; | ||
| 619 | # my $parent_directory_number_of = | ||
| 620 | # $change_a_line->{_parent_directory_number_of}; | ||
| 621 | # my @pathNfile = @{ $change_a_line->{_pathNfile_aref} }; | ||
| 622 | # my @line_of_interest_aref = @{ $change_a_line->{_line_of_interest_aref} }; | ||
| 623 | # | ||
| 624 | # for ( my $parent = 0 ; $parent < $parent_directory_number_of ; $parent++ ) { | ||
| 625 | # | ||
| 626 | # for ( my $child = 0 ; $child < $child_directory_number_of ; $child++ ) { | ||
| 627 | # | ||
| 628 | # my @pathNfile_list = @{ $pathNfile[$parent][$child] }; | ||
| 629 | # my $pathNfile_list_length = scalar @pathNfile_list; | ||
| 630 | # | ||
| 631 | # for ( my $i = 0 ; $i < $pathNfile_list_length ; $i++ ) { | ||
| 632 | # | ||
| 633 | # # slurp every file | ||
| 634 | # $manage_files_by2->set_pathNfile( $pathNfile_list[$i] ); | ||
| 635 | # my $slurp_ref = | ||
| 636 | # manage_files_by2->get_whole( $pathNfile_list[$i] ); | ||
| 637 | # my @slurp = @$slurp_ref; | ||
| 638 | # | ||
| 639 | # my @line_number = | ||
| 640 | # @{ $line_of_interest_aref[$parent][$child][$i] }; | ||
| 641 | # my $line_number_of = scalar @line_number; | ||
| 642 | # | ||
| 643 | # if ( $line_number_of > 0 ) { | ||
| 644 | # | ||
| 645 | # foreach my $line (@line_number) { | ||
| 646 | # | ||
| 647 | # chomp $slurp[$line]; | ||
| 648 | # | ||
| 649 | # # substitute "= module" with "= module->new->new()" | ||
| 650 | # print("3. found line $slurp[$line]\n"); | ||
| 651 | # $slurp[$line] =~ s/=\snew\s/=\ /g; | ||
| 652 | # $slurp[$line] =~ s/\(\)//g; | ||
| 653 | # $slurp[$line] =~ s/;/->new\(\);/g; | ||
| 654 | # print("new line =$slurp[$line]\n"); | ||
| 655 | # | ||
| 656 | # } | ||
| 657 | # | ||
| 658 | # print("Hit Enter to continue\n"); | ||
| 659 | # <STDIN>; | ||
| 660 | # | ||
| 661 | # # open( OUT, ">$pathNfile_list[$i]" ) | ||
| 662 | # # or die("File $pathNfile_list[$i] not found"); | ||
| 663 | # # | ||
| 664 | # # foreach my $text (@slurp) { | ||
| 665 | # # print OUT $text . "\n"; # add \n!!!! | ||
| 666 | # # print("$text \n"); | ||
| 667 | # # } | ||
| 668 | # # | ||
| 669 | # # close(OUT); | ||
| 670 | # | ||
| 671 | # } | ||
| 672 | # else { | ||
| 673 | # # print("\npathNfile_list=$pathNfile_list[$i]\n"); | ||
| 674 | # # print("main,no matching lines detected\n"); | ||
| 675 | # } | ||
| 676 | # | ||
| 677 | # } # for files in a list | ||
| 678 | # | ||
| 679 | # } # for each child directory | ||
| 680 | # | ||
| 681 | # } #for each parent directory | ||
| 682 | # | ||
| 683 | #} # sub replace line of interest | ||
| 684 | # | ||
| 685 | #=head2 set_replacement_type4 | ||
| 686 | # | ||
| 687 | #replace line of interest | ||
| 688 | # | ||
| 689 | #=cut | ||
| 690 | # | ||
| 691 | #sub _set_replacement_type4 { | ||
| 692 | # | ||
| 693 | # my ($self) = @_; | ||
| 694 | # | ||
| 695 | # my $child_directory_number_of = | ||
| 696 | # $change_a_line->{_child_directory_number_of}; | ||
| 697 | # my $parent_directory_number_of = | ||
| 698 | # $change_a_line->{_parent_directory_number_of}; | ||
| 699 | # my @pathNfile = @{ $change_a_line->{_pathNfile_aref} }; | ||
| 700 | # my @line_of_interest_aref = @{ $change_a_line->{_line_of_interest_aref} }; | ||
| 701 | # | ||
| 702 | # for ( my $parent = 0 ; $parent < $parent_directory_number_of ; $parent++ ) { | ||
| 703 | # | ||
| 704 | # for ( my $child = 0 ; $child < $child_directory_number_of ; $child++ ) { | ||
| 705 | # | ||
| 706 | # my @pathNfile_list = @{ $pathNfile[$parent][$child] }; | ||
| 707 | # my $pathNfile_list_length = scalar @pathNfile_list; | ||
| 708 | # | ||
| 709 | # for ( my $i = 0 ; $i < $pathNfile_list_length ; $i++ ) { | ||
| 710 | # | ||
| 711 | # # slurp every file | ||
| 712 | # $manage_files_by2->set_pathNfile( $pathNfile_list[$i] ); | ||
| 713 | # my $slurp_ref = | ||
| 714 | # manage_files_by2->get_whole( $pathNfile_list[$i] ); | ||
| 715 | # my @slurp = @$slurp_ref; | ||
| 716 | # | ||
| 717 | # my @line_number = | ||
| 718 | # @{ $line_of_interest_aref[$parent][$child][$i] }; | ||
| 719 | # my $line_number_of = scalar @line_number; | ||
| 720 | # | ||
| 721 | # if ( $line_number_of > 0 ) { | ||
| 722 | # | ||
| 723 | # for ( my $line = 0 ; $line < $line_number_of ; $line++ ) { | ||
| 724 | # | ||
| 725 | # # CASE only when the search item lies | ||
| 726 | # # on first line | ||
| 727 | # my @temp_string; | ||
| 728 | # | ||
| 729 | # if ( $line == 0 ) { | ||
| 730 | # chomp $slurp[$line]; | ||
| 731 | # | ||
| 732 | # # double check | ||
| 733 | # @temp_string = split( /\s+/, $slurp[$line] ); | ||
| 734 | # | ||
| 735 | # if ( $temp_string[0] ne 'package' ) { | ||
| 736 | # | ||
| 737 | # print("4.$temp_string[0],$temp_string[1]\n"); | ||
| 738 | # print( | ||
| 739 | # "4. current file is $pathNfile_list[$i]\n"); | ||
| 740 | # print( | ||
| 741 | # "4.found line $slurp[$line] on line=$line\n" | ||
| 742 | # ); | ||
| 743 | # | ||
| 744 | # $slurp[$line] =~ s/use\ aliased\ \'/package\ /g; | ||
| 745 | # print("new line =$slurp[$line]\n"); | ||
| 746 | # | ||
| 747 | # print("Hit Enter to continue\n"); | ||
| 748 | # <STDIN>; | ||
| 749 | # | ||
| 750 | # open( OUT, ">$pathNfile_list[$i]" ) | ||
| 751 | # or die("File $pathNfile_list[$i] not found"); | ||
| 752 | # | ||
| 753 | # foreach my $text (@slurp) { | ||
| 754 | # printf OUT $text . "\n"; # add \n!!!! | ||
| 755 | # | ||
| 756 | # # print("$text \n"); | ||
| 757 | # } | ||
| 758 | # | ||
| 759 | # close(OUT); | ||
| 760 | # | ||
| 761 | # } | ||
| 762 | # else { | ||
| 763 | # print( | ||
| 764 | #"exception to type4 search are: @temp_string\n" | ||
| 765 | # ); | ||
| 766 | # } | ||
| 767 | # } | ||
| 768 | # else { | ||
| 769 | # # NADA conditional line index=0 | ||
| 770 | # } | ||
| 771 | # | ||
| 772 | # } # for each line in the file | ||
| 773 | # } | ||
| 774 | # else { | ||
| 775 | # # NADA conditional if search cases exist | ||
| 776 | # } | ||
| 777 | # | ||
| 778 | # } # for each file in a list | ||
| 779 | # } # for each child direcroty | ||
| 780 | # } # for each parent directory | ||
| 781 | #} # sub replace line of interest | ||
| 782 | # | ||
| 783 | #=head2 set_replacement_type5 | ||
| 784 | # | ||
| 785 | #replace line of interest | ||
| 786 | # | ||
| 787 | #=cut | ||
| 788 | # | ||
| 789 | #sub _set_replacement_type5 { | ||
| 790 | # | ||
| 791 | # my ($self) = @_; | ||
| 792 | # | ||
| 793 | # my $child_directory_number_of = | ||
| 794 | # $change_a_line->{_child_directory_number_of}; | ||
| 795 | # my $parent_directory_number_of = | ||
| 796 | # $change_a_line->{_parent_directory_number_of}; | ||
| 797 | # my @pathNfile = @{ $change_a_line->{_pathNfile_aref} }; | ||
| 798 | # my @line_of_interest_aref = @{ $change_a_line->{_line_of_interest_aref} }; | ||
| 799 | # | ||
| 800 | # for ( my $parent = 0 ; $parent < $parent_directory_number_of ; $parent++ ) { | ||
| 801 | # | ||
| 802 | # for ( my $child = 0 ; $child < $child_directory_number_of ; $child++ ) { | ||
| 803 | # | ||
| 804 | # my @pathNfile_list = @{ $pathNfile[$parent][$child] }; | ||
| 805 | # my $pathNfile_list_length = scalar @pathNfile_list; | ||
| 806 | # | ||
| 807 | # for ( my $i = 0 ; $i < $pathNfile_list_length ; $i++ ) { | ||
| 808 | # | ||
| 809 | # # slurp every file | ||
| 810 | # $manage_files_by2->set_pathNfile( $pathNfile_list[$i] ); | ||
| 811 | # my $slurp_ref = | ||
| 812 | # manage_files_by2->get_whole( $pathNfile_list[$i] ); | ||
| 813 | # my @slurp = @$slurp_ref; | ||
| 814 | # | ||
| 815 | # my @line_number = | ||
| 816 | # @{ $line_of_interest_aref[$parent][$child][$i] }; | ||
| 817 | # my $line_number_of = scalar @line_number; | ||
| 818 | # | ||
| 819 | # if ( $line_number_of > 0 ) { | ||
| 820 | # | ||
| 821 | # for ( my $line = 0 ; $line < $line_number_of ; $line++ ) { | ||
| 822 | # | ||
| 823 | # my @temp_string; | ||
| 824 | # chomp $slurp[ $line_number[$line] ]; | ||
| 825 | # | ||
| 826 | # # double check | ||
| 827 | # @temp_string = | ||
| 828 | # split( /=\s/, $slurp[ $line_number[$line] ] ); | ||
| 829 | # | ||
| 830 | # if ( $temp_string[1] eq "'1.00';" ) { | ||
| 831 | # | ||
| 832 | # print("\n4.$temp_string[0] = $temp_string[1]\n"); | ||
| 833 | # print("4. current file is $pathNfile_list[$i]\n"); | ||
| 834 | # print( | ||
| 835 | #"4.found line $slurp[$line] on line=$line_number[$line]\n" | ||
| 836 | # ); | ||
| 837 | # | ||
| 838 | # print("Hit Enter to continue"); | ||
| 839 | # <STDIN>; | ||
| 840 | # $slurp[ $line_number[$line] ] =~ | ||
| 841 | # s/\'1.00\'/\'1.0.0\'/g; | ||
| 842 | # print("\t4.Change:$slurp[$line_number[$line]]\n"); | ||
| 843 | # | ||
| 844 | # open( OUT, ">$pathNfile_list[$i]" ) | ||
| 845 | # or die("File $pathNfile_list[$i] not found"); | ||
| 846 | # | ||
| 847 | # foreach my $text (@slurp) { | ||
| 848 | # | ||
| 849 | # print OUT $text . "\n"; # add \n!!!! | ||
| 850 | # | ||
| 851 | # # print $text."\n"; | ||
| 852 | # | ||
| 853 | # } | ||
| 854 | # | ||
| 855 | # close(OUT); | ||
| 856 | # | ||
| 857 | # } | ||
| 858 | # else { | ||
| 859 | # print( | ||
| 860 | # "exception to type5 search are: @temp_string\n" | ||
| 861 | # ); | ||
| 862 | # } | ||
| 863 | # | ||
| 864 | # } # for each line in the file | ||
| 865 | # } | ||
| 866 | # else { | ||
| 867 | # # NADA conditional if search cases exist | ||
| 868 | # } | ||
| 869 | # | ||
| 870 | # } # for each file in a list | ||
| 871 | # } # for each child directory | ||
| 872 | # } # for each parent directory | ||
| 873 | #} # sub replace line of interest | ||
| 874 | # | ||
| 875 | #=head2 _set_replacement_type6 | ||
| 876 | # | ||
| 877 | #include a new line of interest | ||
| 878 | # | ||
| 879 | #=cut | ||
| 880 | # | ||
| 881 | #sub _set_replacement_type6 { | ||
| 882 | # | ||
| 883 | # my ($self) = @_; | ||
| 884 | # | ||
| 885 | # my $child_directory_number_of = | ||
| 886 | # $change_a_line->{_child_directory_number_of}; | ||
| 887 | # my $parent_directory_number_of = | ||
| 888 | # $change_a_line->{_parent_directory_number_of}; | ||
| 889 | # my @pathNfile = @{ $change_a_line->{_pathNfile_aref} }; | ||
| 890 | # my @line_of_interest_aref = @{ $change_a_line->{_line_of_interest_aref} }; | ||
| 891 | # | ||
| 892 | # for ( my $parent = 0 ; $parent < $parent_directory_number_of ; $parent++ ) { | ||
| 893 | # | ||
| 894 | # for ( my $child = 0 ; $child < $child_directory_number_of ; $child++ ) { | ||
| 895 | # | ||
| 896 | # my @pathNfile_list = @{ $pathNfile[$parent][$child] }; | ||
| 897 | # my $pathNfile_list_length = scalar @pathNfile_list; | ||
| 898 | # | ||
| 899 | # for ( my $i = 0 ; $i < $pathNfile_list_length ; $i++ ) { | ||
| 900 | # | ||
| 901 | # # slurp every file | ||
| 902 | # $manage_files_by2->set_pathNfile( $pathNfile_list[$i] ); | ||
| 903 | # my $slurp_ref = | ||
| 904 | # manage_files_by2->get_whole( $pathNfile_list[$i] ); | ||
| 905 | # my @slurp = @$slurp_ref; | ||
| 906 | # | ||
| 907 | # my @line_number = | ||
| 908 | # @{ $line_of_interest_aref[$parent][$child][$i] }; | ||
| 909 | # my $line_number_of = scalar @line_number; | ||
| 910 | # | ||
| 911 | # if ( $line_number_of > 0 ) { | ||
| 912 | # | ||
| 913 | # for ( my $line = 0 ; $line < $line_number_of ; $line++ ) { | ||
| 914 | # | ||
| 915 | # my @temp_string; | ||
| 916 | # chomp $slurp[ $line_number[$line] ]; | ||
| 917 | # | ||
| 918 | # # double check | ||
| 919 | # @temp_string = | ||
| 920 | # split( /=\s/, $slurp[ $line_number[$line] ] ); | ||
| 921 | # | ||
| 922 | # if ( $temp_string[1] eq "'1.00';" ) { | ||
| 923 | # | ||
| 924 | # print("\n4.$temp_string[0] = $temp_string[1]\n"); | ||
| 925 | # print("4. current file is $pathNfile_list[$i]\n"); | ||
| 926 | # print( | ||
| 927 | #"4.found line $slurp[$line] on line=$line_number[$line]\n" | ||
| 928 | # ); | ||
| 929 | # | ||
| 930 | # my $answer = 'y'; | ||
| 931 | # print(" Change-- Enter n (no) or y (yes)-"); | ||
| 932 | # my $user_ans = <STDIN>; | ||
| 933 | # | ||
| 934 | # if ( $user_ans eq 'n' | ||
| 935 | # or not( $user_ans eq 'y' ) ) | ||
| 936 | # { | ||
| 937 | # | ||
| 938 | # $answer = 'n'; | ||
| 939 | # print(" Answer was no\n"); | ||
| 940 | # } | ||
| 941 | # | ||
| 942 | # if ( $answer == 'y' ) { | ||
| 943 | # $slurp[ $line_number[$line] ] =~ | ||
| 944 | # s/\'1.00\'/\'1.0.0\'/g; | ||
| 945 | # print("\tChange:$slurp[$line_number[$line]]\n"); | ||
| 946 | # | ||
| 947 | # open( OUT, ">$pathNfile_list[$i]" ) | ||
| 948 | # or die("File $pathNfile_list[$i] not found"); | ||
| 949 | # | ||
| 950 | # foreach my $text (@slurp) { | ||
| 951 | # | ||
| 952 | # printf OUT $text . "\n"; # add \n!!!! | ||
| 953 | # # print $text."\n"; | ||
| 954 | # | ||
| 955 | # } | ||
| 956 | # | ||
| 957 | # close(OUT); | ||
| 958 | # | ||
| 959 | # } | ||
| 960 | # | ||
| 961 | # } | ||
| 962 | # else { | ||
| 963 | # print( | ||
| 964 | # "exception to type6 search are: @temp_string\n" | ||
| 965 | # ); | ||
| 966 | # } | ||
| 967 | # | ||
| 968 | # } # for each line in the file | ||
| 969 | # } | ||
| 970 | # else { | ||
| 971 | # print("\nfile has no VERSION No.\n"); | ||
| 972 | # print(" file is: $pathNfile_list[$i]"); | ||
| 973 | # | ||
| 974 | # # Search for Moose and put a VERSION number after | ||
| 975 | # # the Moose line | ||
| 976 | # | ||
| 977 | # my $slurp_length = scalar @slurp; | ||
| 978 | # for ( my $line = 0 ; $line < $slurp_length ; $line++ ) { | ||
| 979 | # | ||
| 980 | # chomp $slurp[$line]; | ||
| 981 | # | ||
| 982 | # # double check | ||
| 983 | # my $string = $slurp[$line]; | ||
| 984 | # | ||
| 985 | # if ( $string =~ m/use\sMoose;/ ) { | ||
| 986 | # | ||
| 987 | # print("\n5.string matches Moose at line \n"); | ||
| 988 | # print("5. current file is $pathNfile_list[$i]\n"); | ||
| 989 | # print("5.found $slurp[$line] on line_idx=$line\n"); | ||
| 990 | # print("5.found:$string\n"); | ||
| 991 | # | ||
| 992 | # my $answer = 'y'; | ||
| 993 | # print(" Change-- Enter n (no) or y (yes)-"); | ||
| 994 | # my $user_ans = <STDIN>; | ||
| 995 | # | ||
| 996 | # if ( $user_ans =~ m/y/ ) { | ||
| 997 | # | ||
| 998 | # $answer = 'y'; | ||
| 999 | # print(" Answer was yes\n"); | ||
| 1000 | # | ||
| 1001 | # } | ||
| 1002 | # elsif ( $user_ans =~ m/n/ ) { | ||
| 1003 | # | ||
| 1004 | # $answer = 'n'; | ||
| 1005 | # print(" Answer was no\n"); | ||
| 1006 | # | ||
| 1007 | # } | ||
| 1008 | # else { | ||
| 1009 | # print("Unexpected answer \n"); | ||
| 1010 | # } | ||
| 1011 | # | ||
| 1012 | # if ( $answer eq 'y' ) { | ||
| 1013 | # | ||
| 1014 | # open( OUT, ">$pathNfile_list[$i]" ) | ||
| 1015 | # or die("File $pathNfile_list[$i] not found"); | ||
| 1016 | # | ||
| 1017 | # for ( | ||
| 1018 | # my $count_line = 0 ; | ||
| 1019 | # $count_line <= $line ; | ||
| 1020 | # $count_line++ | ||
| 1021 | # ) | ||
| 1022 | # { | ||
| 1023 | # | ||
| 1024 | # print OUT $slurp[$count_line] | ||
| 1025 | # . "\n"; # add \n!!!! | ||
| 1026 | # | ||
| 1027 | # } | ||
| 1028 | # | ||
| 1029 | # my $insert_line = | ||
| 1030 | # "our \$VERSION = '0.0.1';" . "\n"; # add \n | ||
| 1031 | # print OUT $insert_line; | ||
| 1032 | # | ||
| 1033 | # for ( | ||
| 1034 | # my $count_line = ( $line + 1 ) ; | ||
| 1035 | # $count_line < $slurp_length ; | ||
| 1036 | # $count_line++ | ||
| 1037 | # ) | ||
| 1038 | # { | ||
| 1039 | # | ||
| 1040 | # print OUT $slurp[$count_line] | ||
| 1041 | # . "\n"; # add \n!!!! | ||
| 1042 | # | ||
| 1043 | # } | ||
| 1044 | # | ||
| 1045 | # close(OUT); | ||
| 1046 | # | ||
| 1047 | # } | ||
| 1048 | # | ||
| 1049 | # } | ||
| 1050 | # | ||
| 1051 | # } # for each line in the file | ||
| 1052 | # | ||
| 1053 | # } | ||
| 1054 | # | ||
| 1055 | # } # for each file in a list | ||
| 1056 | # } # for each child directory | ||
| 1057 | # } # for each parent directory | ||
| 1058 | #} # sub replace line of interest | ||
| 1059 | |||
| 1060 | =head2 _set_replacement_type7 | ||
| 1061 | |||
| 1062 | include a new line of interest | ||
| 1063 | |||
| 1064 | =cut | ||
| 1065 | |||
| 1066 | sub _set_replacement_type7 { | ||
| 1067 | |||
| 1068 | my ($self) = @_; | ||
| 1069 | |||
| 1070 | my $child_directory_number_of = $change_a_line->{_child_directory_number_of}; | ||
| 1071 | my $parent_directory_number_of = $change_a_line->{_parent_directory_number_of}; | ||
| 1072 | my @pathNfile = @{ $change_a_line->{_pathNfile_aref} }; | ||
| 1073 | my @line_of_interest_aref = @{ $change_a_line->{_line_of_interest_aref} }; | ||
| 1074 | |||
| 1075 | for ( my $parent = 0 ; $parent < $parent_directory_number_of ; $parent++ ) { | ||
| 1076 | print("at parent#=$parent\n"); | ||
| 1077 | |||
| 1078 | for ( my $child = 0 ; $child < $child_directory_number_of ; $child++ ) { | ||
| 1079 | print("at child#=$child\n"); | ||
| 1080 | my @pathNfile_list = @{ $pathNfile[$parent][$child] }; | ||
| 1081 | my $pathNfile_list_length = scalar @pathNfile_list; | ||
| 1082 | |||
| 1083 | # $pathNfile_list_length =1; | ||
| 1084 | for ( my $i_file = 0 ; $i_file < $pathNfile_list_length ; $i_file++ ) { | ||
| 1085 | |||
| 1086 | print("\n3. current file is $pathNfile_list[$i_file]\n"); | ||
| 1087 | |||
| 1088 | # slurp every file | ||
| 1089 | $manage_files_by2->set_pathNfile( $pathNfile_list[$i_file] ); | ||
| 1090 | my $slurp_ref = | ||
| 1091 | manage_files_by2->get_whole( $pathNfile_list[$i_file] ); | ||
| 1092 | my @slurp = @$slurp_ref; | ||
| 1093 | |||
| 1094 | my @line_number = | ||
| 1095 | @{ $line_of_interest_aref[$parent][$child][$i_file] }; | ||
| 1096 | my $line_number_of = scalar @line_number; | ||
| 1097 | |||
| 1098 | if ( $line_number_of > 0 ) { | ||
| 1099 | |||
| 1100 | for ( my $line = 0 ; $line < $line_number_of ; $line++ ) { | ||
| 1101 | |||
| 1102 | my @temp_string; | ||
| 1103 | chomp $slurp[ $line_number[$line] ]; | ||
| 1104 | |||
| 1105 | # double check | ||
| 1106 | @temp_string = | ||
| 1107 | split( /\s/, $slurp[ $line_number[$line] ] ); | ||
| 1108 | my $number_of_strings = scalar @temp_string; | ||
| 1109 | |||
| 1110 | for ( my $i_string = 0 ; $i_string < $number_of_strings ; $i_string++ ) { | ||
| 1111 | print("temp_string #$i_string =---$temp_string[$i_string]---\n"); | ||
| 1112 | |||
| 1113 | if ( $temp_string[$i_string] =~ m/$line2find/ ) { | ||
| 1114 | |||
| 1115 | print( | ||
| 1116 | "4. current file is $pathNfile_list[$i_file]\n"); | ||
| 1117 | print( | ||
| 1118 | "4.found---$slurp[ $line_number[$line]]---on line=---$line_number[$line]---\n" | ||
| 1119 | ); | ||
| 1120 | |||
| 1121 | my $answer = 'y'; | ||
| 1122 | print(" Change-- Enter n (no) or y (yes)-\n"); | ||
| 1123 | chomp( my $user_ans = <STDIN> ); | ||
| 1124 | |||
| 1125 | if ( $user_ans eq 'n' | ||
| 1126 | or not( $user_ans eq 'y' ) ) | ||
| 1127 | { | ||
| 1128 | |||
| 1129 | $answer = 'n'; | ||
| 1130 | print(" Answer was no\n"); | ||
| 1131 | } | ||
| 1132 | |||
| 1133 | if ( $answer eq 'y' ) { | ||
| 1134 | |||
| 1135 | $slurp[ $line_number[$line] ] = | ||
| 1136 | "AUTHOR: Juan Lorenzo (Perl module only)"; | ||
| 1137 | print( | ||
| 1138 | "\tChange is:--$slurp[$line_number[$line]]\n\n" | ||
| 1139 | ); | ||
| 1140 | open( OUT, ">$pathNfile_list[$i_file]" ) | ||
| 1141 | or | ||
| 1142 | die("File $pathNfile_list[$i_file] not found"); | ||
| 1143 | |||
| 1144 | my $local_line_text=0; | ||
| 1145 | foreach my $text (@slurp) { | ||
| 1146 | |||
| 1147 | printf OUT $text . "\n"; # add \n!!!! | ||
| 1148 | |||
| 1149 | # print ("writing---$text---to file\n"); | ||
| 1150 | # print ("writing---text line#=$local_line_text\n"); | ||
| 1151 | $local_line_text++; | ||
| 1152 | |||
| 1153 | } | ||
| 1154 | |||
| 1155 | close(OUT); | ||
| 1156 | |||
| 1157 | } | ||
| 1158 | else { | ||
| 1159 | |||
| 1160 | print("temp_string_1=$temp_string[1]\n"); | ||
| 1161 | |||
| 1162 | } | ||
| 1163 | |||
| 1164 | } | ||
| 1165 | else { | ||
| 1166 | |||
| 1167 | print( | ||
| 1168 | "exception to type7,temp_string #$i_string =---$temp_string[$i_string]---\n" | ||
| 1169 | ); | ||
| 1170 | |||
| 1171 | } | ||
| 1172 | } # for each part of the line | ||
| 1173 | |||
| 1174 | } # for each line in the file | ||
| 1175 | } | ||
| 1176 | else { | ||
| 1177 | print("\n_set_replacement_type7,file has no lines\n"); | ||
| 1178 | print(" file is: $pathNfile_list[$i_file]\n"); | ||
| 1179 | |||
| 1180 | } # end of if-else-loop | ||
| 1181 | |||
| 1182 | } # for each file in a list | ||
| 1183 | } # for each child directory | ||
| 1184 | } # for each parent directory | ||
| 1185 | } # sub replace line of interest | ||
| 1186 |