Nov 6, 2012, 7:08 AM
Post #5 of 9
Your code is telling me that you explicitly told perl not to tell you why it was failing.
Re: [stevieger] variables for moving files
[In reply to]
Start by adding these 2 prgmas to your script.
They should be in every Perl script you write.
The strict pragma will force you to declare your vars, which is done with the 'my' keyword.
You should ALWAYS check the return code of an open call to verify that it was successful and take action if it wasn't. You should use a lexical var for the filehandle instead of the bareword and you should use the 3 arg form of open.
Since you haven't shown us the contents of data.txt, I must ask: are the source and destination on separate lines and are they the only 2 lines in the file? If the answer is no to either of those questions, then that would be the source of the problem.
open my $fh, '<', 'data.txt' or die "failed to open 'data.txt' $!";
chomp (my ($file, $dirTo) = <$fh>);
print "Taking $file and putting in $dirTo";
move($file, $dirTo) or die "failed to move '$file' to '$dirTo' $!";