Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
laziness, impatience, and hubris
 
PerlMonks  

Re^5: Is there a way to avoid copy function from overwriting old contents?

by furry_marmot (Pilgrim)
on Apr 12, 2011 at 19:59 UTC ( #899046=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Is there a way to avoid copy function from overwriting old contents?
in thread Is there a way to avoid copy function from overwriting old contents?

Why do you use File::Copy? I tested your code and, to my surprise, copy does append to a file if you open it for appending and copy to the filehandle.

copy "file1", $fh
But it's not documented in the POD, and it only works as a side effect of how File::Copy deals with filehandles. Why not do as others have suggested:
if (true) { open (my $fh, ">> RESULT_LOG"); open BATTERY, "<Battery_Status"; print $fh <BATTERY>; close BATTERY; } else {print "Error"}
It's a couple of extra lines, but you can use all built-ins, obviating the need for an external module.

My two cents.

--marmot


Comment on Re^5: Is there a way to avoid copy function from overwriting old contents?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-04-20 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls