Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

copy, cp or syscopy of File::Copy?

by szabgab (Priest)
on Feb 24, 2013 at 11:18 UTC ( #1020390=perlquestion: print w/replies, xml ) Need Help??
szabgab has asked for the wisdom of the Perl Monks concerning the following question:

In a recent article I wrote How to copy a file with Perl, and Reini Urban commented that I should use either syscopy or cp of File::Copy, rather than its copy function.

I have not found any indication for problems in the documentation of the module. Could I get the opinion of the Perl Monks?

Replies are listed 'Best First'.
Re: copy, cp or syscopy of File::Copy?
by duelafn (Vicar) on Feb 24, 2013 at 13:34 UTC

    There is a difference between copy and cp. From File::Copy:

    ... as of version 2.15, "cp" will preserve the source file's permission bits like the shell utility cp(1) would do, while "copy" uses the default permissions for the target file (which may depend on the process' "umask", file ownership, inherited ACLs, etc.). ...

    In summary:
    copy: copy file with default permissions
    cp: copy file preserving permissions
    syscopy: not actually sure what it does (doesn't preserve owner or permissions in Linux)

    Being a Linux user, I'm not actually sure what filesystem oddness syscopy is trying to address. It seems that in Linux, "cp" is the best option. It may be that syscopy is best on other OSes (assuming what you really want is a true copy of all file properties).

    Update: Fixed some descriptions after testing a bit.

    Good Day,

Re: copy, cp or syscopy of File::Copy?
by Anonymous Monk on Feb 24, 2013 at 11:38 UTC

    Makes no difference and "cp" isn't documented

    I've never had a problem in over a decade, so I won't UTSL to try to decipher what rurban is talking about -- outburst without substance

      outburst without substance?
      if you have no idea what you are talking about, don't do it. if you never had a problem you are probably not deep enough into it, and you obviously never looked into the differences and accepted the wrong defaults.

      copy was the simple idea of perl IO copying, block per block, allowing handles, but it did not care about OS specific settings, like preserving permissions or ownership. This was a big issue over and over and p5p never cared. This was fixed finally a few releases ago (2.15 exactly), but there are still older perls around which use the old simple copy, loosing file attributes. The problem is mostly in os-compat Makefiles, which does use ExtUtils::Command cp for copying files, i.e. executables or shared libs, which loose there x bit after that treatment.

      syscopy uses the system provided syscopy and preserves attribs on most OS, and cp uses the cp(1) utility with filenames, if available.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1020390]
Approved by tinita
[shmem]: Lady_Aleena, in the first example grep evaluates the result from grep and if true, returns $_. In the second, it always returns $_
[shmem]: ..the result from the pattern match
[Lady_Aleena]: tobyink, I did after I failed to get the BLOCK to work. I can't seem to get my brain around grep BLOCK, though I'm okay with grep EXPR.
[shmem]: so in the second example grep returns all true elements of the list passed
[Lady_Aleena]: Okay, so grep BLOCK is not like map BLOCK where something might need to be returned at the end.
[tobyink]: grep { $_ =~ /.*$in.*/; } @my_modules should work just fine. The problem is that you were adding on ;$_ at the end of the block. Why were you doing that?
[Lady_Aleena]: tobyink, I was thinking map.
[tobyink]: Something does need to be returned at the end not $_ though. You need to return (something that will be evaluated as) a boolean.
[Lady_Aleena]: Here is a longish map I did in the same script. my @my_modules = map { my $file = $_; $file =~ s/$module_director y(.+)\.pm/$1/; $file =~ s/\//::/g; $file; } @files;
[Lady_Aleena]: I spent half an hour trying to figure out why map was rewriting @files.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-05-27 07:42 GMT
Find Nodes?
    Voting Booth?