in reply to Trouble opening files from a directory: "no such file".

There is another way to do this, I find it a lot easier to use glob() to get a list of files.

my @files = glob("$dir/*.txt");
@files then contains all the files that match the filename expansion. BTW glob doesn't use regex but expands filenames like the unix shell.

It's a lot less typing anyway ;)

Also, you could use File::Slurp to read the files.

use File::Slurp; my $text = read_file($filename); # or my @lines = read_file($filename);

Replies are listed 'Best First'.
Re^2: Trouble opening files from a directory: "no such file".
by Corion (Patriarch) on Aug 10, 2011 at 12:22 UTC

    Using the normal glob function directly fails if $dir contains directories with whitespace in them. It's better to use the bsd_glob function of File::Glob, or alternatively, to appropriately quote the whitespace in the arguments to glob.