Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How to copy a file

by Bloodrage (Monk)
on Feb 27, 2008 at 21:04 UTC ( [id://670754]=note: print w/replies, xml ) Need Help??


in reply to How to copy a file

Perl can handle multiple filehandles at once...
open OLD "<", $oldfile or die "Can't open $oldfile ($!)\n"; open NEW ">", $newfile or die "Can't open $newfile ($!)\n"; print NEW while(<OLD>); close OLD; close NEW;
err... didn't actually test that... but I'm sure it works :)

Replies are listed 'Best First'.
Re^2: How to copy a file
by runrig (Abbot) on Feb 28, 2008 at 22:38 UTC
    File::Copy will at least copy more than a line at a time...by default 2Mb at a time for files, 1k for non-files. Which is likely preferable to one line at a time. But I think I'd go with system("cp ...")
Re^2: How to copy a file
by ack (Deacon) on Feb 28, 2008 at 21:43 UTC

    I have used this approach numerous times (though after I discovered File::Copy I've used it much more). The only thing I missed (typical of my not seeing all the power one can get into a single line) is the 'print NEW while(<OLD>)' single line.

    I am curious that in the original Anonymous Monk's code the input from OLD is to a scalar, doesn't that just read in a single record from the OLD document?

    ack Albuquerque, NM

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-18 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found