#!/usr/bin/perl -w use diagnostics; my $source_dir = "/home/haim/tmp/lists"; sub init_source_list { chdir $source_dir or die "Cannot change dir to $source_dir! ($!)"; while (defined($sourcefile = glob("*"))) { # for every file in this # directory if (-d $sourcefile) { # if the file is actually a directory... while (defined($ver = glob("$sourcefile/*"))) { #$ver =~ s/.*\///; #remove everything before the "/". $apps{$sourcefile}{$ver} = undef; # add an empty key to # %apps{$sourcefile} } } else { $apps{$sourcefile} = undef; # add an empty key in the hash # %apps } } } &init_source_list; foreach $key (keys %apps) { if (keys %{ $apps{$key} }) { foreach $vkey (keys %{ $apps{$key} }) { print "$source_dir/$key/$vkey\n"; } } else { print "$source_dir/$key\n"; } } #### sub init_source_list { chdir $source_dir or die "Cannot change dir to $source_dir! ($!)"; while (defined($sourcefile = <*>)) { # for every file in this # directory if (-d $sourcefile) { # if the file is actually a directory... chdir "$sourcefile"; while (defined($ver = <*>)) { $ver =~ s/.*\///; #remove everything before the "/". $apps{$sourcefile}{$ver} = undef; # add an empty key to # %apps{$sourcefile} } chdir "$source_dir"; } else { $apps{$sourcefile} = undef; # add an empty key in the hash # %apps } } }