FAQ 5.5 How can I copy a file?
FAQ 5.5 How can I copy a file?
am 05.10.2007 21:03:02 von PerlFAQ Server
This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
------------------------------------------------------------ --------
5.5: How can I copy a file?
(contributed by brian d foy)
Use the File::Copy module. It comes with Perl and can do a true copy
across file systems, and it does its magic in a portable fashion.
use File::Copy;
copy( $original, $new_copy ) or die "Copy failed: $!";
If you can't use File::Copy, you'll have to do the work yourself: open
the original file, open the destination file, then print to the
destination file as you read the original.
------------------------------------------------------------ --------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
Re: FAQ 5.5 How can I copy a file?
am 05.10.2007 23:02:21 von rvtol+news
PerlFAQ Server schreef:
> use File::Copy;
But not before reading some of
http://www.google.co.uk/search?q=file.copy+abigail
http://perl.abigail.be/Talks/FC/HTML/
--
Affijn, Ruud
"Gewoon is een tijger."
Re: FAQ 5.5 How can I copy a file?
am 06.10.2007 20:54:45 von brian d foy
In article , Dr.Ruud
wrote:
> PerlFAQ Server schreef:
>
> > use File::Copy;
>
> But not before reading some of
> http://www.google.co.uk/search?q=file.copy+abigail
>
> http://perl.abigail.be/Talks/FC/HTML/
Indeed, although I think we should fix File::Copy so it doesn't have
those problems. I'm not sure why nobody hasn't.
Re: FAQ 5.5 How can I copy a file?
am 07.10.2007 12:41:52 von Michele Dondi
On Sat, 06 Oct 2007 13:54:45 -0500, brian d foy
wrote:
>> http://perl.abigail.be/Talks/FC/HTML/
>
>
>Indeed, although I think we should fix File::Copy so it doesn't have
>those problems. I'm not sure why nobody hasn't.
I know Abigail is concerned about F::C's UI when it comes to copy
several files to a directory, which is of course a good point and a
pov one cannot but share. Anyway I suppose that just fixing this,
plain and simple, may break backwards compatibility in (the admittedly
but not completely improbable) case someone had been relying on the
broken behaviour that's been there for years. Annoying as it may be,
the fixed one should probably be implemented through some sort of
switch.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: FAQ 5.5 How can I copy a file?
am 07.10.2007 23:04:13 von Ben Morrow
Quoth brian d foy :
> In article , Dr.Ruud
> wrote:
>
> > PerlFAQ Server schreef:
> >
> > > use File::Copy;
> >
> > But not before reading some of
> > http://www.google.co.uk/search?q=file.copy+abigail
> >
> > http://perl.abigail.be/Talks/FC/HTML/
>
>
> Indeed, although I think we should fix File::Copy so it doesn't have
> those problems. I'm not sure why nobody hasn't.
Because it's Hard. The most important advantage to using cp(1), AFAICS,
is that it knows about attributes files have that are particular to your
OS; writing a Perl module to locate and copy all of these is not an easy
task.
Ben
Re: FAQ 5.5 How can I copy a file?
am 08.10.2007 04:43:03 von Kevin Michael Vail
In article ,
Ben Morrow wrote:
> Quoth brian d foy :
> > In article , Dr.Ruud
> > wrote:
> >
> > > PerlFAQ Server schreef:
> > >
> > > > use File::Copy;
> > >
> > > But not before reading some of
> > > http://www.google.co.uk/search?q=file.copy+abigail
> > >
> > > http://perl.abigail.be/Talks/FC/HTML/
> >
> >
> > Indeed, although I think we should fix File::Copy so it doesn't have
> > those problems. I'm not sure why nobody hasn't.
>
> Because it's Hard. The most important advantage to using cp(1), AFAICS,
> is that it knows about attributes files have that are particular to your
> OS; writing a Perl module to locate and copy all of these is not an easy
> task.
So maybe File::Copy should use 'cp' behind the scenes on Unix?
--
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@vaildc.net | blazing high above your head.
. . . . . . . . . | But _in_ you is the presence that
. . . . . . . . | will be, when all the stars are dead.
. . . . . . . . . | (Rainer Maria Rilke)
Re: FAQ 5.5 How can I copy a file?
am 08.10.2007 11:19:15 von Michele Dondi
On Sun, 7 Oct 2007 22:04:13 +0100, Ben Morrow
wrote:
>Because it's Hard. The most important advantage to using cp(1), AFAICS,
>is that it knows about attributes files have that are particular to your
>OS; writing a Perl module to locate and copy all of these is not an easy
>task.
BTW: isn't cp's code available from a shared lib for which bindings
could be built for Perl?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Re: FAQ 5.5 How can I copy a file?
am 08.10.2007 15:00:38 von Ben Morrow
Quoth Michele Dondi :
> On Sun, 7 Oct 2007 22:04:13 +0100, Ben Morrow
> wrote:
>
> >Because it's Hard. The most important advantage to using cp(1), AFAICS,
> >is that it knows about attributes files have that are particular to your
> >OS; writing a Perl module to locate and copy all of these is not an easy
> >task.
>
> BTW: isn't cp's code available from a shared lib for which bindings
> could be built for Perl?
Not on my system. I believe some (?) Linuxes have such a library, but
most systems don't.
Ben
Re: FAQ 5.5 How can I copy a file?
am 08.10.2007 15:31:09 von brian d foy
In article , Ben Morrow
wrote:
> Quoth brian d foy :
> > Indeed, although I think we should fix File::Copy so it doesn't have
> > those problems. I'm not sure why nobody hasn't.
> Because it's Hard.
Hard problems are the fun ones. :)