help concatenation of files
help concatenation of files
am 14.04.2009 19:38:27 von zilore mumba
--===============0972743826==
Content-Type: multipart/alternative; boundary="0-475216749-1239730707=:99218"
--0-475216749-1239730707=:99218
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Dear Perl Users,
In the program below, am trying to put many text files into one. The progra=
m creates the directories as desired, moves the files to the directories as=
per commands and creates an output file.
But the file created is empty and the error message is indicated as the pat=
h specified is not found. Am not sure exactly which line is not correct.
Help will be appreciated.
Zilore Mumba
=A0
=A0
#!/usr/bin/perl -w
use strict;
use warnings;
use POSIX;
use File::Path;
use File::Copy;
#
my $debug =3D 0;
#
my @now =3D localtime;
=A0my ($day, $mon, $year) =3D (localtime(time() - 60 * 60 * 24) ) [ 3,4,5];
=A0
=A0$year =3D $year+1900;
=A0$mon =3D $mon+1;
=A0open(DAT_OUT, ">datefile.txt");
=A0printf DAT_OUT ("%04d%02d%02d\n", $year, $mon,$day);
=A0close OUT;
=A0open(DAT_OUT, "
te in a file so that month is tow-digit
=A0my $dat0=3D;
=A0chomp $dat0;
=A0close OUT;
=A0my $msg_pref =3D 'msgs';
=A0my $ext =3D'.txt';
=A0my $out_file =3D "$dat0$msg_pref$ext";
=A0my $msg_dir =3D 'Messages';
if ( ! -d $msg_dir ) { # Create a directory called Messages
=A0 print "mkpath $dat0\n" if $debug;
=A0 mkpath ($msg_dir ) or die "mkpath '$msg_dir' failed: $! ($^E)";
}
=A0
my $cmd01 =3D "mv msg* $msg_dir";=A0 # Move all messages to directory Messa=
ges
print "doing system ($cmd01)\n" if $debug;
system ($cmd01);
=A0chdir ($msg_dir) or die "cd to '$msg_dir' failed: $! ($^E)";
=A0 # Change directory to directory Messages
if ( ! -d $dat0 ) {
=A0 print "mkpath $dat0\n" if $debug;
=A0 mkpath ($dat0) or die "mkpath '$dat0' failed: $! ($^E)";
=A0 } # Create a directory called by yesterday's da=
te
# Move all files to date_directory
=A0 my $cmd02 =3D "mv msg* $dat0"; # Move all messages to date directo=
ry
=A0 print "doing system ($cmd02)\n" if $debug;
=A0 system ($cmd02); =A0#But program remains in Messages
# open output file - in dat0 #
#
=A0 print "Creating output file '$out_file'\n" if $debug;
=A0 open OUT, ">$dat0/$out_file" or die "Create '$out_file: failed $! ($^E)=
";
=A0 my @files =3D();
=A0 opendir DIR, "$dat0" or die "opendir '$dat0' Failed: $! ($^E)";
=A0 while (my $file =3D readdir DIR) {
=A0 next if $file =3D~ m/msg*/;
=A0 print "Adding '$file'\n" if $debug;
=A0 push(@files,$file);
=A0 }
=A0 closedir DIR;
=A0 #my $cmd03 =3D "type @files > $out_file"; =
=A0 # for Windows
=A0 my $cmd03 =3D ("/cygdrive/c/progra~1/pcgrads/win32/cat @files > $out_fi=
le");=20
=A0 print "doing system ($cmd03)\n" if $debug;
=A0 system ($cmd03);
#my $cmd04 =3D "rm msg*";
#print "doing system ($cmd04)\n" if $debug;
#system ($cmd04);
__END__
#
my $files =3D dir() or die "Error doing dir: $!\n";
foreach (@$files) {
=A0 # skip lines not starting with d or -
=A0 if (/^[^d-]/) {
# print "Skipping garbage dir line\n" if $debug;
=A0 next;
=A0 }
#=A0 dir listing
#----0----- -1- ---2---- ---3---- ---4---- -5- -6 --7-- -----8--------
#total 52
#drwx--x--- 3 owner =A0 group =A0 1024 Dec 13=
=A0 1997 .
#drwxr-xr-x 671 owner =A0 group 49152 Dec 18 14:09 .=
..
#-rw-r--r-- 1 xyz =A0 httpd =A0 2010 Sep =
21 13:31 index.htm
=A0 my ($size, $file) =3D (split /\s+/, $_, 9)[4,8]; =A0 # get s=
ize/filename
=A0 next if $file =3D~ /^\.{1,2}$/; =A0 # skip . and=
..
=A0 # if directory - call directory recurse routine
=A0 if (/^d/) {
=A0 ...
=0A
--0-475216749-1239730707=:99218
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
|
top" style=3D"font: inherit;">Dear Perl Users,
In the program below, am trying to put many text files into one. The p=
rogram creates the directories as desired, moves the files to the directori=
es as per commands and creates an output file.
But the file created is empty and the error message is indicated as th=
e path specified is not found. Am not sure exactly which line is not correc=
t.
Help will be appreciated.
Zilore Mumba
#!/usr/bin/perl -w
use strict;
use warnings;
use POSIX;
us=
e File::Path;
use File::Copy;
#
my $debug =3D 0;
#
my @now =
=3D localtime;
my ($day, $mon, $year) =3D (localtime(time() - 60 * 60 * 24) ) [=
3,4,5];
$year =3D $year+1900;
$mon =3D $mon+1;=
open(DAT_OUT, ">datefile.txt");
printf DAT_OUT ("%04=
d%02d%02d\n", $year, $mon,$day);
close OUT;
open(DAT_OUT, "<datefile.txt"); =
# we write date in a file so that month is tow-dig=
it
my $dat0=3D<DAT_OUT>;
chomp $dat0;
clos=
e OUT;
my $msg_pref =3D 'msgs';
my $ext =3D'.txt';
my=
$out_file =3D "$dat0$msg_pref$ext";
my $msg_dir =3D 'Messages';=
DIV>
if ( ! -d $msg_dir ) { # Create a directory ca=
lled Messages
print "mkpath $dat0\n" if $debug;
mkpath =
($msg_dir ) or die "mkpath '$msg_dir' failed: $! ($^E)";
}
=
my $cmd01 =3D "mv msg* $msg_dir"; # Move all messages to directory Me=
ssages
print "doing system ($cmd01)\n" if $debug;
system ($cmd01);
IV>
chdir ($msg_dir) or die "cd to '$msg_dir' failed: $! ($^E)";
=
# Change directory t=
o directory Messages
if ( ! -d $dat0 ) {
print "mkpath $dat0\n=
" if $debug;
mkpath ($dat0) or die "mkpath '$dat0' failed: $! ($^=
E)";
} # Create a=
directory called by yesterday's date
# Move all files to date_directory
my $cmd02 =3D "mv msg* $d=
at0"; # Move all messages to date directory
print "doi=
ng system ($cmd02)\n" if $debug;
system ($cmd02); &nbs=
p; #But program remains in Messages
# open output file - in dat0 #
#
print "Creating output f=
ile '$out_file'\n" if $debug;
open OUT, ">$dat0/$out_file" or =
die "Create '$out_file: failed $! ($^E)";
my @files =3D();
opendir DIR, "$dat0" or die "opendir=
'$dat0' Failed: $! ($^E)";
while (my $file =3D readdir DIR) {
> next if $file =3D~ m/msg*/;
print=
"Adding '$file'\n" if $debug;
push(@files,$file);
> }
closedir DIR;
#my $cmd03 =3D "type @files > $out_file"; &=
nbsp; &nbs=
p; # for Windows
my $cmd03 =3D ("/cygdrive/c/progra~1/pcgra=
ds/win32/cat @files > $out_file");
print "doing system ($cmd0=
3)\n" if $debug;
system ($cmd03);
#my $cmd04 =3D "rm msg*";
#print "doing system ($cmd04)\n" if $debu=
g;
#system ($cmd04);
__END__
#
my $files =3D dir() or die "Error doing dir: $!\n";
foreach (@=
$files) {
# skip lines not starting with d or -
&n=
bsp; if (/^[^d-]/) {
# &n=
bsp; print "Skipping garbage dir line\n" if $debug;
&n=
bsp; next;
}
# dir listing
#----0----- -1- ---2---- ---3---- ---4---- -5- =
-6 --7-- -----8--------
#total 52
#drwx--x--- 3 owner&nbs=
p; group 1024 Dec 13&=
nbsp; 1997 .
#drwxr-xr-x 671 owner group &n=
bsp; 49152 Dec 18 14:09 ..
#-rw-r--r-- 1 x=
yz httpd &=
nbsp; 2010 Sep 21 13:31 index.htm
my ($size, $file) =3D (split /\s+/, $_, 9)[4,8];&nb=
sp; # get size/filename
next if $file =3D=
~ /^\.{1,2}$/; # skip . and ..
IV>
# if directory - call directory recurse routine
V>
if (/^d/) {
=
...
--0-475216749-1239730707=:99218--
--===============0972743826==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0972743826==--
Re: help concatenation of files
am 14.04.2009 22:41:34 von jwkenne
On Apr 14, 2009, at 1:38 PM, zilore mumba wrote:
> Dear Perl Users,
> In the program below, am trying to put many text files into one. The
> program creates the directories as desired, moves the files to the
> directories as per commands and creates an output file.
> But the file created is empty and the error message is indicated as
> the path specified is not found. Am not sure exactly which line is
> not correct.
> Help will be appreciated.
> Zilore Mumba
>
>
> #!/usr/bin/perl -w
> use strict;
> use warnings;
> use POSIX;
> use File::Path;
> use File::Copy;
> #
> my $debug = 0;
> #
> my @now = localtime;
> my ($day, $mon, $year) = (localtime(time() - 60 * 60 * 24) )
> [ 3,4,5];
>
> $year = $year+1900;
> $mon = $mon+1;
> open(DAT_OUT, ">datefile.txt");
> printf DAT_OUT ("%04d%02d%02d\n", $year, $mon,$day);
> close OUT;
> open(DAT_OUT, "
> so that month is tow-digit
> my $dat0=;
> chomp $dat0;
> close OUT;
> my $msg_pref = 'msgs';
> my $ext ='.txt';
> my $out_file = "$dat0$msg_pref$ext";
> my $msg_dir = 'Messages';
> if ( ! -d $msg_dir ) { # Create a directory called Messages
> print "mkpath $dat0\n" if $debug;
> mkpath ($msg_dir ) or die "mkpath '$msg_dir' failed: $! ($^E)";
> }
>
> my $cmd01 = "mv msg* $msg_dir"; # Move all messages to directory
> Messages
> print "doing system ($cmd01)\n" if $debug;
> system ($cmd01);
> chdir ($msg_dir) or die "cd to '$msg_dir' failed: $! ($^E)";
> # Change directory to directory Messages
> if ( ! -d $dat0 ) {
> print "mkpath $dat0\n" if $debug;
> mkpath ($dat0) or die "mkpath '$dat0' failed: $! ($^E)";
> } # Create a directory called by yesterday's date
> # Move all files to date_directory
> my $cmd02 = "mv msg* $dat0"; # Move all messages to date directory
> print "doing system ($cmd02)\n" if $debug;
> system ($cmd02); #But program remains in Messages
> # 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)";
> my @files =();
> opendir DIR, "$dat0" or die "opendir '$dat0' Failed: $! ($^E)";
> while (my $file = readdir DIR) {
> next if $file =~ m/msg*/;
> print "Adding '$file'\n" if $debug;
> push(@files,$file);
> }
> closedir DIR;
> #my $cmd03 = "type @files > $out_file"; # for
> Windows
> my $cmd03 = ("/cygdrive/c/progra~1/pcgrads/win32/cat @files >
> $out_file");
> print "doing system ($cmd03)\n" if $debug;
> system ($cmd03);
> #my $cmd04 = "rm msg*";
> #print "doing system ($cmd04)\n" if $debug;
> #system ($cmd04);
> __END__
> #
> my $files = dir() or die "Error doing dir: $!\n";
> foreach (@$files) {
> # skip lines not starting with d or -
> if (/^[^d-]/) {
> # print "Skipping garbage dir line\n" if $debug;
> next;
> }
> # dir listing
> #----0----- -1- ---2---- ---3---- ---4---- -5- -6 --7-- -----8--------
> #total 52
> #drwx--x--- 3 owner group 1024 Dec 13 1997 .
> #drwxr-xr-x 671 owner group 49152 Dec 18 14:09 ..
> #-rw-r--r-- 1 xyz httpd 2010 Sep 21 13:31 index.htm
> my ($size, $file) = (split /\s+/, $_, 9)[4,8]; # get size/
> filename
> next if $file =~ /^\.{1,2}$/; # skip . and ..
> # if directory - call directory recurse routine
> if (/^d/) {
> ...
What is the /exact/ output of your program?
Do you have Cygwin installed on your system? It is not part of
ActivePerl, and ActivePerl is not part of Cygwin.
Have you indeed the correct path to Cygwin cat there?
--
John W Kennedy
"You can, if you wish, class all science-fiction together; but it is
about as perceptive as classing the works of Ballantyne, Conrad and W.
W. Jacobs together as the 'sea-story' and then criticizing _that_."
-- C. S. Lewis. "An Experiment in Criticism"
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: help concatenation of files
am 14.04.2009 23:51:11 von fzarabozo
> From: zilore mumba
> Sent: Tuesday, April 14, 2009 12:38 PM
> To: activeperl@listserv.activestate.com
> Subject: help concatenation of files
Well, I didn't test anything, but I can see a few things:
You first open DAT_OUT for overwriting, without TESTING for problems with
"or die $!":
> open(DAT_OUT, ">datefile.txt");
And then, you just close OUT, which wasn't open anywhere yet:
> close OUT;
Then, you open DAT_OUT again, this time for read only, and again without
having it tested. Didn't you get a warning or something here?
> open(DAT_OUT, "
Then you assign to a scalar variable. That will only take the
first line, I'm not sure you even need the "chomp" after that:
> my $dat0=;
> chomp $dat0;
And here, AGAIN, you close OUT, which you haven't open anywhere.
> close OUT;
Now, until here you open OUT for overwriting and you actually test it:
> open OUT, ">$dat0/$out_file" or die "Create '$out_file: failed $! ($^E)";
And, after this point, you never do a "print OUT" or a "close OUT", so, no
wonder why your file is coming up empty.
Here's a quick script that would concatenate a series of files into one:
----------------------
use strict;
use warnings;
my @read_files = (
'/path/to/file/1',
'/path/to/file/2',
'/path/to/file/3',
'/path/to/file/4',
'/path/to/file/5',
);
open OUT, ">concatenated_file.txt" or die $!;
for my $i (@read_files) {
open IN, $i or die $!;
print OUT join('', );
close IN;
}
close OUT;
-----------------------
Again, I didn't test anything, neither the sample script I just wrote.
HTH
Paco Zarabozo
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: help concatenation of files
am 15.04.2009 11:01:55 von zilore mumba
--===============0184435080==
Content-Type: multipart/alternative; boundary="0-1413403495-1239786115=:85430"
--0-1413403495-1239786115=:85430
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
--- On Tue, 4/14/09, Bill Luebkert wrote:
From: Bill Luebkert
Subject: Re: help concatenation of files
To: zmumba@yahoo.com
Date: Tuesday, April 14, 2009, 11:05 PM
Bill,
Thank you very much for the code. The name format for the messages is somet=
hing like "msg00001234", i.e msg followed by an 8-digit number. The message=
s are coming continuously and the number is like a serial.
The code you sent me creates "Messages" and date directory eg "20090414". I=
t also creates the out_file in "20090414" but the file is empty.
And I think the code below (starting from opendir does not work because non=
e of the msg files is moved. In fact the files are not in $msg_dir (which i=
s newly create) but are one directory higher
if (! -d $msg_dir) { =A0 # Create a directory called Messages
=A0 print "mkpath $msg_dir\n" if $debug;
=A0 mkpath ($msg_dir) or die "mkpath '$msg_dir': $! ($^E)";
}
opendir DIR, $msg_dir or die "opendir $msg_dir: $! ($^E)";
while ($_ =3D readdir DIR) {
=09# is there a name format for msg files ?=A0 # next if not /???/;
=09next if -d "$msg_dir/$_";
=09print "rename $_, '$msg_dir/$_'\n";
=09rename $_, "$msg_dir/$_" or warn "rename '$_' to
'$msg_dir': $! ($^E)";
}
closedir DIR;
# Change directory to directory Messages
print "chdir $msg_dir\n" if $debug;
chdir $msg_dir or die "chdir '$msg_dir': $! ($^E)";
# Create a directory called by yesterday's date if not there
if (! -d $dat0) {
=09print "mkpath $dat0\n" if $debug;
=09mkpath $dat0 or die "mkpath '$dat0': $! ($^E)";
}
# Move all files to date_directory
opendir DIR, '.' or die "opendir '.': $! ($^E)";
while ($_ =3D readdir DIR) {
=09next if -d $_;
=09print "rename $_, '$dat0/$_'\n";
=09rename $_, "$msg_dir/$_" or warn "rename '$msg_dir/$_':
$! ($^E)";
}
closedir DIR;
# open output file - in dat0
print "Creating output file '$out_file'\n" if $debug;
open OUT, ">>$dat0/$out_file" or die "CreateAp
'$out_file: failed $! ($^E)";
opendir DIR, $dat0 or die "opendir '$dat0': $! ($^E)";
while ($_ =3D readdir DIR) {
=09next if -d $_; next if /^$out_file$/i;
=09print "Adding '$_'\n" if $debug;
=09open IN, "$dat0/$_" or warn "open '$dat0/$_': $!
($^E)";
=09while () {
print OUT;
=09}
=09close IN;
}
closedir DIR;
close OUT;
__END__
=0A
--0-1413403495-1239786115=:85430
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
|
top" style=3D"font: inherit;">
--- On Tue, 4/14/09, Bill =
Luebkert <dbecoll@roadrunner.com> wrote:
16,16,255) 2px solid">
From: Bill Luebkert <dbecoll@roadrunner.com>
Subject: Re: hel=
p concatenation of files
To: zmumba@yahoo.com
Date: Tuesday, April 14=
, 2009, 11:05 PM
Bill,
Thank you very much for the code. The name forma=
t for the messages is something like "msg00001234", i.e msg followed by an =
8-digit number. The messages are coming continuously and the number is like=
a serial.
The code you sent me creates "Messages" and date=
directory eg "20090414". It also creates the out_file in "20090414" but th=
e file is empty.
And I think the code below (starting from
color=3D#000000>opendir does not work because none of the msg files =
is moved. In fact the files are not in $msg_dir
T>(which is newly create) but are one directory highe=
r
=
if (! -d $msg_dir) { # Create a directory called Messages=
print "mkpath $msg_dir\n" if $debug;
=
mkpath ($msg_dir) or die "mkpath '$msg_dir': $! ($^E)";
}
NT>
opendir DIR, $msg_dir or die "opendir $msg_dir: $! ($^=
E)";
while ($_ =3D readdir DIR) {
=09# is there a name format for msg=
files ? # next if not /???/;
=09next if -d "$msg_dir/$_";
=09p=
rint "rename $_, '$msg_dir/$_'\n";
=09rename $_, "$msg_dir/$_" or warn "=
rename '$_' to
'$msg_dir': $! ($^E)";
}
closedir DIR;
# Cha=
nge directory to directory Messages
print "chdir $msg_dir\n" if $deb=
ug;
chdir $msg_dir or die "chdir '$msg_dir': $! ($^E)";
# Create =
a directory called by yesterday's date if not there
if (! -d $dat0) =
{
=09print "mkpath $dat0\n" if $debug;
=09mkpath $dat0 or die "mkpath=
'$dat0': $!
($^E)";
}
# Move all files to date_directory
opendir DIR,=
'.' or die "opendir '.': $! ($^E)";
while ($_ =3D readdir DIR) {
=09=
next if -d $_;
=09print "rename $_, '$dat0/$_'\n";
=09rename $_, "$ms=
g_dir/$_" or warn "rename '$msg_dir/$_':
$! ($^E)";
}
closedir DIR=
;
# open output file - in dat0
print "Creating output file '$=
out_file'\n" if $debug;
open OUT, ">>$dat0/$out_file" or die "Crea=
teAp
'$out_file: failed $! ($^E)";
opendir DIR, $dat0 or die "ope=
ndir '$dat0': $! ($^E)";
while ($_ =3D readdir DIR) {
=09next if -d $=
_; next if /^$out_file$/i;
=09print "Adding '$_'\n" if $debug;
=09ope=
n IN, "$dat0/$_" or warn "open '$dat0/$_': $!
($^E)";
=09while (<I=
N>) {
print OUT;
=09}
=09close IN;
}
closedir DIR;<=
BR>close OUT;
__END__
r>
--0-1413403495-1239786115=:85430--
--===============0184435080==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0184435080==--
RE: help concatenation of files
am 15.04.2009 12:32:04 von Brian Raven
From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of zilore
mumba
Sent: 14 April 2009 18:38
To: activeperl@listserv.activestate.com
Subject: help concatenation of files
> Dear Perl Users,
> In the program below, am trying to put many text files into one. The
program creates the directories as
> desired, moves the files to the directories as per commands and
creates an output file.
> But the file created is empty and the error message is indicated as
the path specified is not found. Am not
> sure exactly which line is not correct.
> Help will be appreciated.
> Zilore Mumba
>
It would help greatly if you provided the exact error message, and
exactly what part of your script caused it. However there is your code
to comment on.
>
> #!/usr/bin/perl -w
> use strict;
> use warnings;
A good start.
> use POSIX;
You might want to change this to 'use POSIX qw{strftime};'. See below.
> use File::Path;
> use File::Copy;
> #
> my $debug = 0;
> #
> my @now = localtime;
> my ($day, $mon, $year) = (localtime(time() - 60 * 60 * 24) ) [
3,4,5];
>
> $year = $year+1900;
> $mon = $mon+1;
> open(DAT_OUT, ">datefile.txt");
You should always check whether the open was successful.
> printf DAT_OUT ("%04d%02d%02d\n", $year, $mon,$day);
> close OUT;
Its probably a good idea to check that the close for an output file
succeeded, because it will likely be here that you learn that your disk
is full.
Also, it's a good idea to close the file handle that you actually opened
and wrote to, not some random one.
> open(DAT_OUT, "
that month is tow-digit
> my $dat0=;
> chomp $dat0;
> close OUT;
Its not clear why you want to write a string to a file, only to read it
in again. Unless you actually need that file for something else, the
above code can be accomplished by:
my $dat0 = strftime "%Y%m%d", localtime(time - 24 * 60 * 60);
> my $msg_pref = 'msgs';
> my $ext ='.txt';
> my $out_file = "$dat0$msg_pref$ext";
> my $msg_dir = 'Messages';
> if ( ! -d $msg_dir ) { # Create a directory called Messages
> print "mkpath $dat0\n" if $debug;
> mkpath ($msg_dir ) or die "mkpath '$msg_dir' failed: $! ($^E)";
> }
>
> my $cmd01 = "mv msg* $msg_dir"; # Move all messages to directory
Messages
> print "doing system ($cmd01)\n" if $debug;
> system ($cmd01);
You need to check whether this command succseeded. See 'perldoc system'
for how. The same applies to following system commands.
> chdir ($msg_dir) or die "cd to '$msg_dir' failed: $! ($^E)";
> # Change directory to directory Messages
> if ( ! -d $dat0 ) {
> print "mkpath $dat0\n" if $debug;
> mkpath ($dat0) or die "mkpath '$dat0' failed: $! ($^E)";
> } # Create a directory called by yesterday's date
> # Move all files to date_directory
> my $cmd02 = "mv msg* $dat0"; # Move all messages to date directory
> print "doing system ($cmd02)\n" if $debug;
> system ($cmd02); #But program remains in Messages
> # 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)";
You never write to this file, or explicitly close it. That being the
case, this file is likely to be empty.
> my @files =();
> opendir DIR, "$dat0" or die "opendir '$dat0' Failed: $! ($^E)";
> while (my $file = readdir DIR) {
> next if $file =~ m/msg*/;
So you are ignoring all files in the date directory which contain the
string "ms" followed by zero or more "g"s. That is, by my reckoning, all
of the files that you previously moved into the date directory with the
command "mv msg* $dat0". Perhaps you mean "next unless $file =~ /^msg/;"
> print "Adding '$file'\n" if $debug;
> push(@files,$file);
> }
> closedir DIR;
> #my $cmd03 = "type @files > $out_file"; # for
Windows
> my $cmd03 = ("/cygdrive/c/progra~1/pcgrads/win32/cat @files >
$out_file");
> print "doing system ($cmd03)\n" if $debug;
> system ($cmd03);
You should probably check that the array @files is not empty before
attempting this command, which I believe is highly likely in this case.
Also, note that the output file created by this command will not be the
same as in the above open function. You use the same name, but write it
to a different directory.
> #my $cmd04 = "rm msg*";
> #print "doing system ($cmd04)\n" if $debug;
> #system ($cmd04);
> __END__
You are aware that everything from this point on will be treated as
comments by perl?
HTH
--
Brian Raven
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy.
Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs