Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I know that I may be over looking somethng in this script. this script works but I trying to automated to run a program that will pick up the file created by the script. I cannot see where would I need to call the IndexImageImport subroutine so it could pick up the file created by the script which was declare as global variable $outfile. I'm trying to recreate it by creating a local variable with the same format as $outfile. For some reason it keeps giving me an error meesage saying that "it does find process file". It means that finds the executable file then it tries to grab the file (%04d%02d%02d.txt)--> 20040603.txt But doesn't find the file to process it. I cannot see why?? Does anyone have any idea? what am I missing in the script to make it fully functional. Please help. Thanks in advance.
#! perl -w use strict; use File::Copy; my $cnt; my $infile = "C:\\dir1\\file.chr"; my ( $yr, $mo, $dy ) = (localtime)[5,4,3]; my $outfile = sprintf( "C:\\radtrans\\%04d%02d%02d.txt",$yr+1900,$mo+1 +,$dy ); my $staticdir = "C:\\dir1\\dir2\\"; my %index; my $filename; open IN, "<$infile" or die "Couldn't open $infile, $!"; open OUT,">$outfile" or die "Couldn't open $outfile, $!"; $cnt++; while (<IN>) { chomp; my @fields = split /\|/; my @newfile = $fields[0]; for (@newfile) { if ($index{$_}) { $filename = $_. $index{$_}; $index{$_}++; } else { $filename = $_; $index{$_} = 'a'; } } my $path_str = $fields[19]; do { warn "Empty field 19"; next } unless $path_str; my @path = split /\\/, $path_str; my $dir = join "\\", @path[ 0, 1, 2, 3, 4, 5, 6 ]; $filename =~ s/$/.rtf/; my $out = join ('|', @fields[0..18]) . "@@" . $staticdir . $filena +me; print OUT "$out\n"; process_dir($dir,$filename); } close IN; sub process_dir { my ($dir, $filename) = @_; do { warn "$dir does not exist!\n"; return } unless -e $dir; opendir DIR, $dir or do { warn "Could not open $dir $!\n" ; return }; while ( my $file = readdir DIR ) { print "dir: $dir file:$file Newfile:$filename\n"; #before the next unless statements. next unless -f "$dir\\$file"; next unless $file =~ m/\.rtf$/i; copy( "$dir\\$file", "C:\\dir1\\dir2\\$filename" ) or die "Failed to copy $file: $!\n"; } indeximageimport; } sub IndexImageImport { my $processfile = sprintf( "%04d%02d%02d.txt",$yr+1900,$mo+1,$dy ); chdir "c:\\Program Files\\Software\\dir1software\\" or die "cannot chd +ir c:\\Program Files\\Software\\dir1software\\: $!"; exec "IndexImageImport.exe /U (user) /W (password) /A Application /S f +ileApp /F C:\\RADTRANS\\$processfile"; die "indeximageimport couldn't run: $!"; }

Replies are listed 'Best First'.
Re: Automation Script to Process file
by Plankton (Vicar) on Jun 03, 2004 at 20:35 UTC
    It might be a good idea to do a ...
    close OUT;
    ... somewhere.

    Plankton: 1% Evil, 99% Hot Gas.
Re: Automation Script to Process file
by Joost (Canon) on Jun 03, 2004 at 20:32 UTC