I've wrote this code and would like to know how to improve it.
It reads the file from one directory and copies them to another. It's really basic I know so I thought I'd better check Im doing it the right way. I tried use strict and that broke it, so thats one line of improvement, are there any more.
#!/usr/local/bin/perl -W # force taint checks, and print warnings
#use strict; # install all three strictures
use File::Copy;
$|++; # force auto flush of output buffer
#define full path to source folder
$path = "sourceDirectory";
#define path to new folder
$newpath = "destinationDirectory";
#recursively search $path for files
opendir (ORIG , $path);
while ($name = readdir(ORIG)){
print "$name\n" ;
@Filenames;
push (@Filenames, $name);
#print " $newpathandfile\n";
}
closedir(ORIG);
chdir($path) || die "cannot move to $path";
foreach $X (@Filenames){
my $destFile = $newpath.$X;
print '$destFile'." = $destFile\n";
copy( "$X" , "$destFile" ) or print "File cannot be copied. $!\n";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.