I'm using the preprocess operation to sort directories and files numerically by 
a 3 digit prefix on the directory name and file name. What I'm after is a 
listing of a directory tree sorted first numerically by directory name and then 
numerically by filename within a directory.  As an example, this is my test 
directory and file structure:

p:/filetest
p:/filetest/010-d1
p:/filetest/020-d2
p:/filetest/020-d2/010-f1.txt
p:/filetest/020-d2/020-f2.txt
p:/filetest/020-d2/030-f3.txt
p:/filetest/030-d3
p:/filetest/030-d3/010-f1.txt
p:/filetest/030-d3/030-f3.txt
p:/filetest/040-d4

The code I used to process this directory structure was:

use File::Find;

find({ wanted => \&process_file,
         preprocess => \&sd},@ARGV[0]);

sub sd {

  sub numerically {

     substr($a,0,3) <=> substr($b,0,3) }  

  my @flist = @_;

  @newlist = sort numerically @flist;

  return @newlist;

} 

  sub process_file {

    print "File: $File::Find::name\n";
}

When I run this on Windows Xp (perl v5.8.4) I get the directory tree listing 
shown earlier, which is what I expected. When I run the same come on Solaris 
5.8 using perl 5.005_03 I get the following result:

File: /filetest
File: /filetest/040-d4
File: /filetest/010-d1
File: /filetest/030-d3
File: /filetest/030-d3/030-f3.txt
File: /filetest/030-d3/010-f1.txt
File: /filetest/020-d2
File: /filetest/020-d2/020-f2.txt
File: /filetest/020-d2/010-f1.txt
File: /filetest/020-d2/030-f3.txt
File: /filetest/test4.pl

As you can see, the directories / files are not sorted according to the numeric 
prefix. 
I'm a newcomer to Perl, so any help would be greatly appreciated.

Thanks



This message and any attachments are intended for the persons named as 
addressees only and may contain confidential information. In addition they may 
be protected by copyright. 

If you receive it in error, notify us, delete it and do not make use of or copy 
it. You must not copy, disseminate or otherwise distribute or publish this 
message, except for the purposes for which this message is intended, without 
our consent. 

Please note that this e-mail has been created in the knowledge that Internet 
e-mail is not a 100% secure communications medium. We advise that you 
understand and accept this lack of security when e-mailing us.

For company information, guidance and forms, please see our website
www.companieshouse.gov.uk.

This message has been scanned for viruses by MailControl, a service from 
BlackSpider Technologies.



_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to