in reply to read an array of file

If all the files end with the .sss extension then you could also do this:
my $path = "/path-to/some-dir"; opendir(DIR, $path) || die "Could not read $path - $!\n"; for my $fileFound (grep /\.sss$/, readdir(DIR)) { # do stuff here... }
Or do the same thing if all the files begin with 'loy':
my $path = "/path-to/some-dir"; opendir(DIR, $path) || die "Could not read $path - $!\n"; for my $fileFound (grep /^loy/, readdir(DIR)) { # do stuff here... }
-- vek --

Replies are listed 'Best First'.
Re: Re: read an array of file
by Jenda (Abbot) on Dec 30, 2002 at 14:08 UTC

    And to complete the original request :

    my $path = "/path-to/some-dir"; opendir(DIR, $path) || die "Could not read $path - $!\n"; for my $fileFound (grep /^loyl\d+i_lgr\.sss$/, readdir(DIR)) { # do stuff here... }
    or
    my $path = "/path-to/some-dir"; opendir(DIR, $path) || die "Could not read $path - $!\n"; while (my $fileFound = readdir(DIR)) { next unless $fileFound =~ /^loyl\d+i_lgr\.sss$/ # do stuff here... }

    The second is better for large directories.

    Jenda