Hello,
I have 2 requirements. First one is I need to move one file at a time to a different file share in order to process the file through ETL. Second is I need to move oldest file first. Below is my code.The files are moving but not by last modification time and also giving 2 different types of error messages.
If I don't use "Use Strict",then here is the message I am getting.
C:\PERL\bin>perl.exe "c:\1file@atime.pl" -e
Global symbol "@sorted" requires explicit package name at c:\1file@ati
+me.pl line
17.
Global symbol "@sorted" requires explicit package name at c:\1file@ati
+me.pl line
26.
Global symbol "$xmlfile" requires explicit package name at c:\1file@at
+ime.pl lin
e 30.
Global symbol "@sorted" requires explicit package name at c:\1file@ati
+me.pl line
30.
Global symbol "$xmlfile" requires explicit package name at c:\1file@at
+ime.pl lin
e 31.
Global symbol "$xmlfile" requires explicit package name at c:\1file@at
+ime.pl lin
e 35.
Execution of c:\1file@atime.pl aborted due to compilation errors.
If I commented out "Use Strict",then it gives below message but files are moving not by sorted time stamp
C:\PERL\bin>perl.exe "c:\1file@atime.pl" -e
Use of uninitialized value in numeric comparison (<=>) at c:\1file@ati
+me.pl line
17.
Use of uninitialized value in numeric comparison (<=>) at c:\1file@ati
+me.pl line
17.
File Name: ebert_conc.con moved to FTP - 30 mins for next upload.
File Name: ebert.xyz moved to FTP - 30 min for next upload.
Here is my script
#!/usr/bin/perl
use warnings;
use strict;
use File::Copy;
my $srcdir = "\\\\windowsservername\\directory\\Subdirectory\\";
my $dest = "C:\\Documents and Settings\\";
for (;;) {
opendir(DIR, $srcdir) or die "Can't open $srcdir: $!";
my @files = grep {!/^\.+$/} readdir(DIR);
@sorted = reverse(sort{ -M $a <=> -M $b
#( $m{$a} ||= -M $a ) <=>
# ( $m{$b} ||= -M $b )
} @files);
close(DIR);
if (!@sorted) {
print "Files have been ended.\n\n";
last;
}
$xmlfile = $sorted[0];
my $old = "$srcdir/$xmlfile";
move($old, $dest) or die "Move $old -> $dest failed: $!";
print "File Name: $xmlfile moved to Fileshare - 30 mins for next u
+pload.\n\n";
sleep 1800; # 30 Minutes
}
I have tried couple other ways but not successful and sure where I am doing wrong.I am using perl version 5.8.8. Any help would be appreciated.
Regards,
Sree
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|