gnu@perl has asked for the wisdom of the Perl Monks concerning the following question:

I need to do an opendir() on a directory glob (ex. /var/gvc/port*/done/). I am aware that under a current perl version I could just use the glob and loop through doing the opendir on $_, but the problem is that the server I am working on is perl -v 5.005_3 and the glob function there is dependant on the system glob wich returns 'argument list too long' when the glob would return over 127 (i think) results.

Any ideas on how I can do this without using a glob?

Below is the subroutine that is doing the work. The glob is what is passed in to the sub (in @_). It should be noted that this sub works fine on the 5.6.0 box, it just blows up on the glob in a 5.005_3 version of perl.

sub { my @files = map { chomp; (< $_ >) } @_; my $return; if (!@files){ $return=0; } else { while (@files){ if (! -f $_){ $return=0; } print "\t Found files:\n\t " . join (",\n\t ", @files) . "\n" if ($DEBUG); $return=1; return $return; } } };

TIA, Chad.

Replies are listed 'Best First'.
Re: opendir on file glob
by gnu@perl (Pilgrim) on Sep 26, 2002 at 19:41 UTC
    DOH! Stupid mistake. I think File::Find and grep() will do exactly what I am looking for.

    I would still like other input, if anyone feels like offering their opinion.