You made a significant start toward finding your problem when you discovered what you say in your comment "not appending." That kind of output error -- after some data acquisition you say is working -- is a pretty broad hint that you should look to your filehandling.
So, for starters, you might have consulted the documentation (perldoc -f open) to check the syntax of open-append:
open (writefile, ">>,$target_full_path") { # quoting changed!
I'd also suggest you change writefile to upper case (or to FH which is one conventional form) to avoid a possible clash with a future reserved word. (use warnings;</c> would have told you this. Well, it would have warned about the possible issue.)
Have you predeclared $rowcount (as a global?). ...$sth4?
Have you considered the benefits of using strict and warnings to help solve questions like this? I'm not clear what kind prior version that would have morphed to this with "slight modifications" COULD have been working.
And, FWIW, a simplified version that does work (with your comments preserved):
use strict;
use warnings;
my $rowcount = 0;
open (FH, ">> 667868.txt") || die "Can't open 667868.txt $!";
while(<DATA>) {
print $_; # it is working
print FH $_; # not appending
$rowcount++; # here it is counting
}
close FH;
print $rowcount;
__DATA__
now is the time
for all good men to
come to the aid of
their country,
while
the quick red fox
jumps over the
lazy brown dog's back.
And, finally, please use <c>...<</c> tags around code. See Writeup Formatting Tips.
UpdateTwo days later: comment re quoting added with thanks to graff for pointing out that OP quoting was OK. |