Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a faster way to do this?

Status
Not open for further replies.

jonlake

MIS
Sep 17, 2003
76
US
my @local_files = glob('c:\\update\\lpt*'); #there could be multiple lpt files, and i need the latest one, signified by a number in the file name so I sort them and get the last one.
my @sorted_files = sort { $a<=>$b; } @local_files;
my $local_size = $#sorted_files;
my $local_latest = $sorted_files[$size];
 
Have you tried to run that code? You should get a bunch of errors similar to: 'Argument... isn't numeric in sort...' In order to sort like that, you'll need to extract the numbers and sort based on the numbers. You can also do away with a lot of those temporary variables/arrays.

Try something like:
Code:
my @sorted = map {$_->[0]}
             sort {$a->[1] <=> $b->[1] ||
                   $a->[0] cmp $b->[0]}
             map {[$_, (m/(\d+)/)]} glob('c:/update/lpt*');
my $local_latest = $sorted[-1];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top