in reply to My habitual errors

I opendir/readdir and forget the initial path when I'm using the results.

opendir my $dh, $dir or die $!; my @files = grep { -f } readdir $dh;

Then I wonder why nothing matches. Or I collect the list of files and wonder why they all fail to open. In fact, I recently passed this habitual error on to another wisdom-seeker.

Replies are listed 'Best First'.
Re^2: My habitual errors
by Moron (Curate) on Apr 05, 2007 at 11:41 UTC
    I used to have that same problem, so what I did was create a convention for myself where $dir is the directory, $file is the filename without directory and $path is the two together and make sure that having assigned $path = "$dir/$file", that $dir and $file do not appear further down the same routine (only $path and $dh, the directory handle assigned to $dir)

    -M

    Free your mind