I think this is what you are trying to do:

Others have pointed out some of the problems with this script, system("cd d:") doesn't effect the rest of the progrem, etc. Others remain unnoted so far (recursive function call to answer(), use of & on function calls).

Here's my UNTESTED rough cut at a rewrite. Here's what I already know is wrong with it. I haven't enabled taint checking for the file names. I don't untaint the file names. There is almost certainly a better way to run those perl scripts against the target file. The subroutines need block comments describing what they do. Script paths are hardcoded in the body of the script and not in variables or constants at the top of the file. The temporary and base paths are specified in list form, which isn't too familiar to many people, I should really use File::Spec to parse normal paths. Finally it is UNTESTED code that features the dangerous unlink command. Despite all this, it may be a useful starting point for you.

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 = <STDIN>; 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 = <STDIN>; 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 } } }


TGI says moo


In reply to Re: ActivePERL is the devil? by TGI
in thread ActivePERL is the devil? by james734

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.