Assuming the files are numbered with a fixed width, such as three digits that you have here in your example, you can sort the output of readdir and pick off the first entry. If you're not familiar with this method, try this:
my $base_dir = "c:/data/"; my $new_dir = "d:/new/"; opendir (DIR, $base_dir) || die "Could not open data directory\n"; my ($top_file) = reverse sort readdir(DIR); closedir (DIR);
Note that this is assigning the first element of the sorted, reversed array from readdir into $top_file. As sort usually goes from lowest to highest (i.e. a .. z), using reverse will give you the highest.

If your files have a variable number of digits, this sort routine will fail miserably, as the order will be something like 1, 10, 11, 2, 20. You will have to write a "custom" numerical sort routine: my ($top_file) = reverse sort { ($a=~/\$(\d+)$/)<=>($b=~/\$(\d+)$/) } readdir(DIR); Which has the effect of extracting the numerical component from each entry (\d+ is one or more digits). An interesting twist is that you can switch $a and $b and remove reverse because you are now defining the sort rules.

To move the file from one drive to another is, if I recall correctly, something that might require the use of File::Copy. As in:
use File::Copy; move($base_dir.$top_file, $new_dir.$top_file);

In reply to Re: Sorting on Files by tadman
in thread Sorting on Files by Perl Newby

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.