Alan C. wrote at Thu, 07 Aug 2003 02:34:32 -0700:

> It's my  .*  attempt I don't understand, seek help on.  (seek/need 
> ability to either all files in dir opened or pattern search the files in 
> dir with only files that meet pattern opened)
> 
> [...]
>
> my $filspec = '.*'; # brings error: permission denied at line 18
> 
> my $fildir = '/Programs/NOTETA~2/DOCUME~1';
> opendir(FILDIR,$fildir)|| die "can't open $fildir $!";
> 
> my @fils = grep /$filspec/,readdir FILDIR;

Note that .* or .txt as a regular expression is different from the meaning
that it has in e.g. a dir command.

.txt stands for a pattern of 4 characters where the first one can be
anything (except a newline) and the three following are just txt.
E.g. atxt would match /.txt/.

Similar .* stands for a pattern of any character that occurs zero or more
often. E.g. an empty string (containing zero characters) _matches_ the
pattern.

In your case, I'd guess that also the pseudo directories "." and ".." are
readout by the readdir command what has of course to fail later.

I would emphasize to you to use the perl function glob.

my @file = glob("$filedir/$filespec");

what will work with
$filespec = "*.txt";   #  Note that the star * is not redundant
# or
$filespec = "*.*";

Note also that with glob, the directory name is already in the elements of
@file.

For details, please read
perldoc -f glob


Your program should be able to rewritten as:

use strict;
use warnings;

my $pattern = '(?=.*\bmodule\b)';

my $filespec = '*.*';
my $filedir = '/Programs/NOTETA~2/DOCUME~1';

foreach my $file (glob "$filedir/$filespec") {
     open(FILE,$file) or die "can't $!";
     while (<FILE>) {
         if (s/^H=($pattern)/$1/io) {
             print "$file:$_" ;
         }
     }
     close FILE;
}

Greetings,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to