in reply to Directory Listing

OK so this is marginally better:
opendir(DIRH, '.') or die "cant open $!"; my %file = map { $_ => (stat($_))[10]} grep !/^\.\.?/ && /.*pm$/, readdir DIRH; closedir DIRH; for (reverse sort { $file{$a} cmp $file{$b} } keys %file) { print "value : $_ , $file{$_} \n"; }

Replies are listed 'Best First'.
Re: Re: Directory Listing
by chipmunk (Parson) on Jan 09, 2001 at 19:48 UTC
    There is almost never a need to use a map and a grep one after the other; they can be combined into a single loop. my %file = map { /^[^.].*\.pm$/ ? ($_ => (stat $_)[10]) : () } readdir DIRH; For each item, if the regex matches, return a two element list (that's the map part), otherwise return an empty list (that's the grep part).

    I combined the original poster's two regexes as well, and made the match a little more explicit.