hi
while traversing a filesystem i want to output a list of all files
grouped by file extensions.
this is no problem in itself but in the output i want the file names to
appear in their correct sorted or nested order (which is in the order
they entered the hash).
considering the test script below i have a for loop that can do the
order for me (but no filenames) and a while loop that can produce the
filenames (but unordered).

my end result in this specfic example should be like:

.pl

(1) -> :folder_one:byte.pl
(2) -> :folder_one:compare.pl
(5) -> :folder_one:folder_two:cool.pl
(6) -> :folder_one:folder_two:nested.pl
(7) -> :folder_one:folder_two:folder_three:hash.pl
(9) -> :folder_one:folder_two:folder_three:last.pl


.gif

(3) -> :folder_one:some.gif
(4) -> :folder_one:folder_two:pic.gif
(8) -> :folder_one:folder_two:folder_three:b_.gif
(10) -> :folder_one:folder_two:folder_three:last.gif


thanks
allan
____________________________________________________


#! perl -w

use strict;
my %hash_of_file_extensions;

$hash_of_file_extensions{".pl"}{1}   = ":folder_one:byte.pl";
$hash_of_file_extensions{".pl"}{2}   = ":folder_one:compare.pl";
$hash_of_file_extensions{".gif"}{3}  = ":folder_one:some.gif";
$hash_of_file_extensions{".gif"}{4}  = ":folder_one:folder_two:pic.gif";
$hash_of_file_extensions{".pl"}{5}   = ":folder_one:folder_two:cool.pl";
$hash_of_file_extensions{".pl"}{6}   = ":folder_one:folder_two:nested.pl";
$hash_of_file_extensions{".pl"}{7}   = ":folder_one:folder_two:folder_three:hash.pl";
$hash_of_file_extensions{".gif"}{8}  = ":folder_one:folder_two:folder_three:b_.gif";
$hash_of_file_extensions{".pl"}{9}   = ":folder_one:folder_two:folder_three:last.pl";
$hash_of_file_extensions{".gif"}{10} = ":folder_one:folder_two:folder_three:last.gif";


print "this does not produce the file name\n\n";
for my $extension (keys %hash_of_file_extensions) {
        print $extension . "\n\n";
        for my $level (sort by_number(keys
%{$hash_of_file_extensions{$extension}})) {
                print "($level) -> ?\n";
        }
        print "\n\n";
}

print "this produces everthing but unordered\n\n";
while ((my $extension, my $innerHash) = each %hash_of_file_extensions) {
        print $extension . "\n\n";
        while ((my $file_reference, my $filename) = each %$innerHash) { 
                print "($file_reference) -> $filename\n";
        }
        print "\n\n";
}

sub by_number {
        $a <=> $b;
}
__END__

Reply via email to