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

Dear Monks, My code is working but I need to accomplish a final task. It is by producing a report at the end. I need to print out all fields within the file except the last field which is the new path with an @ symbol. Do you have any suggestions on where to print the OUTPUT file? will need to create the ouput file after the files get rename or while it is happenning. Any suggestions would be appreciated. For example:
270917,0382469, ,WILLIAMS,ALICE,5/28/2003, ,AARON WOLFSON,JOHNSON, MAR +CIA,/NURSING/STATUS NOTE,A2903007,5/29/2003@@C:\TestFiles\$newfile
#! perl -w use strict; use File::Copy; my $infile = "C:/zip files misc/doclisth.chr"; my $outfile = "C:/zip files misc/radtrans.txt"; open IN, "<$infile" or die "Couldn't open $infile, $!"; open OUT,">$outfile" or die "Couldn't open $outfile, $!"; while (<IN>) { chomp; my @fields = split /,/; my $newfile = $fields[0]; my $path_str = $fields[13]; do { warn "Empty field 14"; next } unless $path_str; my @path = split /\\/, $path_str; my $dir = join "\\", @path[ 0, 1, 2, 3, 4, 5, 6 ]; process_dir($dir,$newfile); } close IN; sub process_dir { my ($dir, $newfile) = @_; 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:$newfile\n"; #before the next unless statements. next unless -f "$dir\\$file"; next unless $file =~ m/\.rtf$/i; $newfile =~ s/$/.rtf/; copy( "$dir\\$file", "C:\\testfile\\$newfile" ) or die "Failed to copy $file: $!\n"; } }

Replies are listed 'Best First'.
Re: How to print a report to file
by chromatic (Archbishop) on Jun 05, 2003 at 23:54 UTC

    If you explicitly return a success value from process_dir(), you could check for success or failure within your while loop and log there.