in reply to Re: getting files from Dir
in thread getting files from Dir
Personally, I'd wrap the whole thing in a do block and use grep, so that I don't need to track my handles explicitly:my @wanted; opendir my $dh, $dir or die "Failed opening $dir: $!"; foreach (readdir $dh) { next unless /^tim(\d+)/; my $num = $1; push @wanted, $_ if $num > 14 and $num < 51; } closedir $dh;
Note that when you assign a match's captures to a list, failed expressions will return undef, so here I can implicitly test for success by testing the definedness of $num.my @tim_file = do { opendir my $dh, $dir or die "Failed opening $dir: $!"; grep { my ($num) = /^tim(\d+)/; defined $num and $num > 14 and $num < 51; } readdir $dh; };
Makeshifts last the longest.
|
|---|