in reply to File::Random module
From http://search.cpan.org/perldoc/Path::Iterator::Rule#SYNOPSIS, you add whatever checks you need, same algorithm as File::Random, it reads the whole directory tree but only one filename at a time in memory
sub random_file { my @dirs = @_; my $rule = Path::Iterator::Rule->new; # match anything $rule->file->size(">10k"); # add/chain rules # iterator interface my $next = $rule->iter( @dirs ); my $random_file; my $i = 0; while ( my $file = $next->() ) { if( rand $i++ < 1 ){ $random_file = $file; } } return $random_file; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: File::Random module (Path::Iterator::Rule)
by gautamparimoo (Beadle) on Apr 02, 2013 at 10:40 UTC | |
by marto (Cardinal) on Apr 02, 2013 at 10:46 UTC | |
by gautamparimoo (Beadle) on Apr 02, 2013 at 11:02 UTC | |
by xdg (Monsignor) on Apr 02, 2013 at 13:38 UTC | |
by McA (Priest) on Apr 02, 2013 at 13:45 UTC | |
by Anonymous Monk on Apr 02, 2013 at 11:04 UTC |