use strict; use warnings; use diagnostics; use File::Copy; use File::Spec; use Cwd; use Shell 'perl'; my @TEMP_PATH = ( 'D:', 'perl' ); my @BASE_PATH = ( 'D:', 'tmp' ); my $base_path = File::Spec->catdir( @BASE_PATH ); my $file = get_file_to_process( $base_path ); my $orig_file = File::Spec->catfile( @BASE_PATH, $file); my $temp_file = File::Spec->catfile( @TEMP_PATH, $file); process_file( $orig_file, $temp_file ); if ( keep_changes() ) { # Copy the editted file over the original copy( $temp_file, $orig_file ); } # Cleanup unlink $temp_file; # ------------------------------------ sub print_listing { my $dir_path = shift; my $curdir = cwd; # Change scripts working directory to TEMP_PATH chdir( $dir_path ); # Get a list of *.txt files using glob. # You could also use opendir to do this. while ( my $filename = glob('*.txt') ) { print "$filename\n"; } chdir( $curdir ); } sub get_file_to_process { my $base_path = shift; print_listing( $base_path ); print "Enter File Name to be converted.\n"; print "File should be in this directory.\n"; my $file = ; chomp $file; # Test for existence die "File $file does not exist\n" unless -e $file; } sub process_file { my $orig_file = shift; my $temp_file = shift; # Copy the file into a temporary location. copy( $orig_file, $temp_file ) or die "Unable to create temp file $temp_file - $!\n"; # Here we edit the temporary file # instead of using it as a backup. print "Staring Edits...1."; perl "/perl/macc1", $temp_file; sleep 2; print ",13.\n"; perl "/perl/macc13", $temp_file; print "Edits complete.\n"; } sub keep_changes { print "Do you wish to keep the edits?\n"; print "Enter Yes or No.\n"; my $response = ; chomp $response; while (1) { if ( $response =~ /^y(es)?$/i ) { return 1; } elsif ( $response =~ /^no?$/i ) { return; } else { print <<'END_MSG'; ===================================== You Have Entered and Incorrect Option Valid Options are [Y/N] ===================================== END_MSG } } }