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

In reply to Sort files by oldest timestamp by srianju

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.