> From: zilore mumba
> Sent: Tuesday, April 14, 2009 12:38 PM
> To: [email protected]
> 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, "<datefile.txt");
Then you assign <DAT_OUT> to a scalar variable. That will only take the
first line, I'm not sure you even need the "chomp" after that:
> my $dat0=<DAT_OUT>;
> 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('', <IN>);
close IN;
}
close OUT;
-----------------------
Again, I didn't test anything, neither the sample script I just wrote.
HTH
Paco Zarabozo
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs