Dear Perl Community,
Based on the very constructive comments I received from many, and on the script
provided by Bill I have modified my script as below. This time I create only
one (date) directory and move all files (in current directory)there and
concatenate them. I am getting an error in creation of dtae directory and
cannot figure out the source of error. I have indicated by ### where the error
occurs.
Help appreciated
Good day
Zilore
#!/usr/bin/perl --
use strict;
use warnings;
use POSIX;
use File::Path;
use File::Copy;
my $debug = 1;
my @now = localtime;
my ($day, $mon, $year) = (localtime (time - 86400))[3,4,5];
$year = $year + 1900;
$mon = $mon + 1;
my $dat0 = sprintf ("%04d%02d%02d\n", $year, $mon, $day);
my $ext = '.txt';
my $out_file = "$dat0$ext";
print "out_file='$out_file'\n" if $debug;
# Create a directory called by yesterday's date if not there
if ( ! -d $dat0 ) { ### Error here
print "mkpath $dat0\n" if $debug;
mkpath ($dat0) or die "mkpath '$dat0' failed: $! ($^E)"; ### €rror here
}
# Move all files to date_directory
opendir DIR, '.' or die "opendir '.': $! ($^E)";
while ($_ = readdir DIR) {
next if -d $_;
print "rename $_, '$dat0/$_'\n";
rename $_, "$dat0/$_" or warn "rename '$dat0/$_': $! ($^E)";
}
closedir DIR;
# open output file - in dat0
print "Creating output file '$out_file'\n" if $debug;
open OUT, ">>$dat0/$out_file" or die "Create '$out_file: failed $! ($^E)";
opendir DIR, $dat0 or die "opendir '$dat0': $! ($^E)";
while ($_ = readdir DIR) {
next if -d $_; next if /^$out_file$/i;
print "Adding '$_'\n" if $debug;
open IN, "$dat0/$_" or warn "open '$dat0/$_': $! ($^E)";
while (<IN>) {
print OUT;
}
close IN;
}
closedir DIR;
close OUT;
__END__
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs