[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

PERL Copy command not working for me

Posted on 2009-04-10
5
Medium Priority
?
1,005 Views
Last Modified: 2012-05-06
I am trying to copy one file from one directory to another..

use File::Copy;
use File::Path;
copy("begperl/MODE3.txt","BASELINE/MODE4.txt"); but for some reason it's not calling an error and it is not copying the file either :'( i also tried this:
 
sub copy
{ my($from, $to) = @_;
  if(open(IN, $from))
  {  if(open(OUT, ">$to"))
     {  while(read IN, $buf, 4096)
        {   print OUT $buf;
        }
        close IN;
        close OUT;
        }
     close IN;
  }
}
 
&copy("/begperl/MODE3.txt","/BASELINE/MODE4.txt");
 
and nothing :'( do you know where my mistake could be? thankssssssss :) you're awesome :)

Open in new window

0
Comment
Question by:cucugirl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 24118842
You should display the error when it doesn't succeed:
    copy("begperl/MODE3.txt","BASELINE/MODE4.txt") or die "Could not copy: $!\n";

Or when you open:
    if(open(IN, $from)) {
       ...
    }
    else {
        die "Could not open input: $!\n";
    }

0
 

Author Comment

by:cucugirl
ID: 24118897
Could not copy: No such file or directory
it's weird though because the file exists.. M:\begperl and M:\BASELINE
im trying to copy the file from begperl to BASELINE

thanks! for that tip :)
0
 
LVL 48

Expert Comment

by:Tintin
ID: 24119444
That file may exist, but you have specified a relative path rather than an absolute path.

Use

copy "M:/begperl/MODE3.txt","M:/BASELINE/MODE4.txt" or die "Could not copy MODE3.txt because $!\n";
0
 
LVL 13

Expert Comment

by:marchent
ID: 24172108
Use the windows copy command directly using function system();

system("copy M:/begperl/MODE3.txt M:/BASELINE/MODE4.txt");
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 24172293
marchent>>Use the windows copy command directly using function system()

Doing this, you don't know if the command is successful.  It'd be better to fail and know it than to fail and not know it.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question