Adrian Bowden wrote:
> 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 = @_;
Try dumping the before and after @flist/@newlist to see what's happening.
> @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.
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs