#! /usr/bin/perl -W
use File::Copy::Recursive qw (dircopy);
use warnings;
print "Hi this is a script to copy a file \n";
print " Enter the name of the file to be copied with the compete path\
+n";
$Source = <STDIN>;
chomp($Source);
print "Enter the full path of the Destination \n";
$Destination = <STDIN>;
chomp($Destination);
if( -e $Source)
{ print "copying $Source to $Destination \n";
dircopy($Source, $Destination) or die "File cannot be copied: $!
+";
}
else
{ print " The File does not Exist \n";
}
I personally don't like having code after the opening brace ({) of a code block, but I didn't change that as it's only a preference, and doesn't affect readability/maintainability/etc.
I'd also advise you to error-check things as soon as possible, rather than later. It simplifies code flow in most cases, and keeps related things together. Consider this version of your program:
#! /usr/bin/perl -W
use File::Copy::Recursive qw (dircopy);
use warnings;
print "Hi this is a script to copy a file \n";
print " Enter the name of the file to be copied with the compete path\
+n";
$Source = <STDIN>;
chomp($Source);
if ( -e $Source)
{ die " The File does not Exist \n";
}
print "Enter the full path of the Destination \n";
$Destination = <STDIN>;
chomp($Destination);
print "copying $Source to $Destination \n";
dircopy("$Source","$Destination") or die "File cannot be copied.";
...roboticus
When your only tool is a hammer, all problems look like your thumb. |