Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

link() error: Cross-device link

Status
Not open for further replies.

whn

Programmer
Oct 14, 2007
265
US
I want to copy a file from /var to /tmp in perl. When I use link(), I got this error: Cross-device link. Though it is understandable, what is the solution then?

I know I can do it using system("cp $oldfile $newfile"), or I can use file read/write to create the file through a loop. But, neither is ideal way to do this.

Could someone here know a better way?

Many thanks.
 
File::Copy ??

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Sorry, I should have done more research before I asked q question here.

I found the solution at CPAN:

use File::Copy;
copy("file1","file2") or die "Copy failed: $!";
 
Oh, thank you travs, I did not see your reply. Sorry.

I was writing the above follow-up post and then dragged away. I should have double checked it before I submit.

Again, thank you, travs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top