>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
#! perl $fileNames = << "EOF"; :folder_one:byte.pl :folder_one:compare.pl :folder_one:some.gif :folder_one:folder_two:pic.gif :folder_one:folder_two:cool.pl :folder_one:folder_two:nested.pl :folder_one:folder_two:folder_three:hash.pl :folder_one:folder_two:folder_three:b_.gif :folder_one:folder_two:folder_three:last.pl :folder_one:folder_two:folder_three:last.gif EOF @files = split(/\n/,$fileNames); for $f (0..$#files) { ($x, $ext) = split(/\./,$files[$f]); $extension{$ext} .= " $files[$f]\n"; } foreach $x (sort keys(%extension)) { print "$x\n$extension{$x}\n"; } __END__ David Seay http://www.mastercall.com/g-s/