Hi!
Steve Dawson wrote:
Have you considered asking the users to use a numeric sequenceon the files?
Yes, I have. The problem is they have used the aforementioned
nomenclature from the DOS era and their answer was along the lines of
"we've been doing this since the dawn of mankind and we don't intend to
change this now". To just rename the files would be madness, especially
on several thousands of files which they have now. They have also not
been inclined to use a different versioning system for any new projects
as "the old guys would have to get used to it and we'd have a mess of
things". If you can't beat them... (use a bigger stick ;))
...
The problem I have is when instead of an array @files_a I get one like
@files_v, which contains letters from the end of the alpahbet and the
beginning, which should mean that the users ran out of letters and
began from a, b, ... again.
...
I don't get why they'd start a sequence halfway through the alphabet...
I assume that there is never more than 23 parts to the file (22 alpha's
+ the base).
They have a script which scans the files periodically and usually just
leaves the last few versions of their projects on the disks.
The desired sort order would be something like:
- first the file without the version letter, ie. ends with a number
(if it exists)
- then a-z
...
@newarray = sort @oldarray; '.' (0x2e) will sort before 'a' (0x61) so
that seems pretty simple.
Indeed :)
...
In case of @files_b like arrays:
- first the file without the version letter (if it exists)
- then versions from the last part of the alphabet
- versions from the first part of the alphabet
...
Merge the basename, head and tail arrays into a custom sorted array and
you're done.
See code below for a quick stab at how it could be done...
Thank you for your code, I will definitely try it out :) In the meantime
I have come up with the following solution which seems to work for the
time being.
First I take a look at the versions and if both versions "a" and "z"
exist in an array of files. If so, I use this sort:
@newlist = sort round_robin_sort @filelist;
# use only if both a and z versions are found
sub round_robin_sort
{
# drop extension
@alist = split (/\./, $a);
@blist = split (/\./, $b);
# drop the extension
pop @alist;
pop @blist;
$aver = chop ($alist[$#alist]);
$bver = chop ($blist[$#blist]);
# number/no version is always first on the list
if ($aver =~ /[0-9]/) { return -1; }
elsif ($bver =~ /[0-9]/) { return 1; }
# if versions are from different halves of the alphabet
elsif (($aver =~ /[a-k]/) && ($bver =~ /[l-z]/)) { return 1; }
elsif (($bver =~ /[a-k]/) && ($aver =~ /[l-z]/)) { return -1; }
# if both are from first or last half of the alphabet, just cmp
else { return $aver cmp $bver; }
}
Else I use
@newlist = sort @filelist;
So far it seems to work ok.
Thank you and everyone else for your help with this problem!
Cheers,
Miha
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs