in reply to Re: list of fles in a directory, but use wildcards like *
in thread list of fles in a directory, but use wildcards like *

When I was using,
opendir DIR, $dir; my @file = grep { $_ ne '.' && $_ ne '..' } readdir DIR; closedir DIR;
to list all files in the directory, opening those files with,
foreach $file (@file){ open(MYFILE, $dir.$file[$i]) or die qq(Cannot open $file[$i]\n); ....some other stuff
would work. But now using the glob, it's dying when open the files in the files list.

Replies are listed 'Best First'.
Re: Re: Re: list of fles in a directory, but use wildcards like *
by LordWeber (Monk) on Sep 04, 2003 at 17:30 UTC
    Re: Re: Re: list of fles in a directory, but use wildcards like *
    by graff (Chancellor) on Sep 05, 2003 at 05:06 UTC
      foreach $file (@file){ open(MYFILE, $dir.$file[$i]) or die qq(Cannot open $file[$i]\n); ...
      Well, in addition to the previous comment about the directory path (which is correct), this snippet would not do what you want because you aren't setting $i; you are using the scalar $file as an iterator variable, which is being set to successive elements of array @file, but then in the loop you are always using the "$i'th" element of @file, and you don't show any indication that this (totally unnecessary) array index counter is being set or incremented.

      On top of that, your error report is misleading: you try to open a file called  $dir.$file[$i] and when that fails, you only report trying to open  $file[$i], so you would never know when the problem is due to the content of $dir.