« lib/App/SeismicUnixGui/big_streams/iVpicks2par.pm
↑ Summary
lib/App/SeismicUnixGui/misc/copyNclean_sgy_up.pl »
| 1 | use Moose; | ||
| 2 | =head1 DOCUMENTATION | ||
| 3 | |||
| 4 | =head2 SYNOPSIS | ||
| 5 | |||
| 6 | count | ||
| 7 | |||
| 8 | PERL PROGRAM NAME: copyNclean_segy_up.pl | ||
| 9 | AUTHOR: Juan Lorenzo | ||
| 10 | DATE: Nov. 23 2023 | ||
| 11 | |||
| 12 | DESCRIPTION | ||
| 13 | count occurrences of strings in a list | ||
| 14 | |||
| 15 | BASED ON: | ||
| 16 | |||
| 17 | =cut | ||
| 18 | |||
| 19 | =head2 USE | ||
| 20 | |||
| 21 | =head3 NOTES | ||
| 22 | |||
| 23 | =cut | ||
| 24 | |||
| 25 | my $content_ref = &wanted('./'); | ||
| 26 | my @content = @$content_ref; | ||
| 27 | |||
| 28 | copy_up($content_ref); | ||
| 29 | |||
| 30 | exit; | ||
| 31 | |||
| 32 | sub wanted { | ||
| 33 | my ($path2look) = @_; | ||
| 34 | |||
| 35 | use File::Slurp; | ||
| 36 | my @content = read_dir( $path2look, prefix => 1 ); | ||
| 37 | |||
| 38 | my $result = \@content; | ||
| 39 | |||
| 40 | return ($result); | ||
| 41 | } | ||
| 42 | |||
| 43 | =head2 sub clean | ||
| 44 | |||
| 45 | Removes leading zeros and | ||
| 46 | chages sgy to segy suffix. | ||
| 47 | |||
| 48 | =cut | ||
| 49 | sub clean { | ||
| 50 | my ($array_ref) = @_; | ||
| 51 | my @names; | ||
| 52 | |||
| 53 | foreach my $val (@$array_ref) { | ||
| 54 | $val =~ s/^.\/0+//; | ||
| 55 | $val =~ s/sgy/segy/; | ||
| 56 | push @names, $val; | ||
| 57 | } | ||
| 58 | my $result = \@names; | ||
| 59 | |||
| 60 | return($result); | ||
| 61 | } | ||
| 62 | |||
| 63 | sub copy_up { | ||
| 64 | my ($array_ref) = @_; | ||
| 65 | |||
| 66 | my $new_name; | ||
| 67 | my $old_name; | ||
| 68 | |||
| 69 | # pre-condition | ||
| 70 | my @old_name = @$array_ref; | ||
| 71 | print @old_name; | ||
| 72 | |||
| 73 | my $clean_name_aref = &clean($array_ref); | ||
| 74 | my @clean_name = @$clean_name_aref; | ||
| 75 | my $num_names = scalar @clean_name; | ||
| 76 | |||
| 77 | for (my $i=0; $i< $num_names; $i++){ | ||
| 78 | |||
| 79 | if ( $old_name[$i] ne './copy.pl' | ||
| 80 | and $old_name[$i] ne '../') { | ||
| 81 | |||
| 82 | $new_name = "../".$clean_name[$i]; | ||
| 83 | system("cp $old_name[$i] $new_name"); | ||
| 84 | print ("copy $old_name[$i] $new_name \n"); | ||
| 85 | } else { | ||
| 86 | print ("will not cp copy.pl or ../ \n"); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | } |