Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: appending data to a file

by ww (Archbishop)
on Feb 14, 2008 at 03:14 UTC ( #667872=note: print w/replies, xml ) Need Help??


in reply to appending data to a file

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.

Replies are listed 'Best First'.
Re^2: appending data to a file
by graff (Chancellor) on Feb 14, 2008 at 03:34 UTC
    So, for starters, you might have consulted the documentation (perldoc -f open) to check the syntax of open-append:
    open (writefile, ">>,$target_full_path") {

    Um, the OP actually started with:

    open (writefile, ">>",$target_full_path) {
    which is a perfectly acceptable use of the 5.8 "three-arg open" calling style, so that's not the problem, and there's no need to "fix" it. (I would object to the use of an all-lower-case bareword for the file handle -- either make ALLCAPS or else use a "my" variable for that -- but that's a separate matter.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://667872]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2020-10-24 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (246 votes). Check out past polls.

    Notices?