Hi,
I am really having a tough time writing a perl script that will read all the files in a directory and transfer them to another directory on my computer.
Please, could anyone tell me what is likely wrong with the code or help me
with a better one. I am just a day old using perl. Thanks for your help.
#!/usr/local/bin/perl -w
$forcefiles="/Users/agboma/Desktop/TEST/TEST_DAILY_WB/forcing/";
opendir(FORCING, $forcefiles) || die("Cannot open directory");
@thefiles=grep !/^\.\.?$/,readdir(FORCING);
foreach $dataset (@thefiles) {
print "$dataset\n";
open(FILE,$dataset) ||die("Could not open $dataset\n");
open(OUTFILE,">/Users/agboma/Desktop/perl_learn/$dataset") ||die("Could not
open for output $dataset\n");
$line=<FILE>;
while ($line ne "") {
print OUTFILE($line);
$line=<FILE>;
}
}
I am using the terminal in MAC OSX to run perl .This is the error I get when I run the code:
.DS_Store
Use of uninitialized value in string ne at files.pl line 14.
data_33,5625_100.6875
Could not open data_33,5625_100.6875
I am really having a tough time writing a perl script that will read all the files in a directory and transfer them to another directory on my computer.
Please, could anyone tell me what is likely wrong with the code or help me
with a better one. I am just a day old using perl. Thanks for your help.
#!/usr/local/bin/perl -w
$forcefiles="/Users/agboma/Desktop/TEST/TEST_DAILY_WB/forcing/";
opendir(FORCING, $forcefiles) || die("Cannot open directory");
@thefiles=grep !/^\.\.?$/,readdir(FORCING);
foreach $dataset (@thefiles) {
print "$dataset\n";
open(FILE,$dataset) ||die("Could not open $dataset\n");
open(OUTFILE,">/Users/agboma/Desktop/perl_learn/$dataset") ||die("Could not
open for output $dataset\n");
$line=<FILE>;
while ($line ne "") {
print OUTFILE($line);
$line=<FILE>;
}
}
I am using the terminal in MAC OSX to run perl .This is the error I get when I run the code:
.DS_Store
Use of uninitialized value in string ne at files.pl line 14.
data_33,5625_100.6875
Could not open data_33,5625_100.6875