http://qs321.pair.com?node_id=368779


in reply to rtfm

You could also reduce memory overhead (at the expense of more calls to rand) by doing your random keep/toss within the loop:
my $lines = 0; my $selection; foreach my $path (split /:/, $ENV{'PATH'}) { opendir(PATH, $path); while (defined($_ = readdir(PATH))) { if (-f "$path/$_") { ++$lines; $selection = $_ if int(rand($lines)) == 0; } } closedir(PATH) } exec(man => $selection);

We're not really tightening our belts, it just feels that way because we're getting fatter.