in reply to specifying file extension in opendir function

Hi greatshots,

opendir doesn't allow wildcards, as it is not designed to list filenames, but to open a special file, that is a directory.

In the perldoc for opendir (perldoc -f opendir) you have an small example filtering filenames from an opendir and readdir, using grep. You can do something similar:

opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; + @tdefs = grep { /\.tdef$/ && -f "$some_dir/$_" } readdir(DIR); closedir DIR;


Replies are listed 'Best First'.
Re^2: specifying file extension in opendir function
by greatshots (Pilgrim) on Nov 16, 2006 at 11:28 UTC
    thanks a lot themage. most of the time I am using the solution which you have given to acheive my requirement. thanks a lot for spending your valuable time for reading my node and replied for that.
Re^2: specifying file extension in opendir function
by Anonymous Monk on Nov 16, 2010 at 22:03 UTC
    $some_dir I don't know what $some_dir has to be written, newbie says. :(