Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: appending data to a file

by kyle (Abbot)
on Feb 14, 2008 at 03:11 UTC ( #667871=note: print w/replies, xml ) Need Help??


in reply to appending data to a file

Here's the code as I've deciphered it:

open (writefile,">>",$target_full_path) || die "Can't open $target_ful +l_path"; while($fetchdata=$sth4->fetchrow_array()) { print $fetchdata; #it is working print writefile $fetchdata; # not appending $rowcount++; #here it is counting } close writefile; print $rowcount;

When you open, it doesn't die? Maybe try printing $target_full_path to make sure it has what you think it does. Your argument to die should include $! in it somewhere since that will have the error that caused open to fail.

I'm sorry, I don't see why this wouldn't work. What was the slight modification that causes it to break?

Replies are listed 'Best First'.
Re^2: appending data to a file
by papidave (Pilgrim) on Feb 14, 2008 at 14:52 UTC
    Are you really trying to capture the return value of $sth->fetchrow_array() in a scalar? Your comments imply that you're seeing data on STDOUT from the first print $fetchdata;, but I don't see how it could be the data you wanted. The DBI docs suggest:

    while ( @row = $sth->fetchrow_array ) { print "@row\n"; }

    That said, it seems to me that you'd likely run into trouble if the return value were ever an empty string ("") or something else that evaluates to FALSE.

Re^2: appending data to a file
by bipinbalan (Initiate) on Feb 14, 2008 at 07:50 UTC
    Hi,
      I think this code will work. Check it..
    open (writefile,">>$target_full_path") || die "Can't open $target_full +_path"; while($fetchdata=$sth4->fetchrow_array()) { print $fetchdata; print writefile $fetchdata; $rowcount++; #here it is counting } close writefile; print $rowcount;
    Cheers !
      Bipin Balan

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2020-01-22 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?