On Wed, Jan 09, 2002 at 05:05:34PM -0000, Parker, wrote:
> Hi all,
>
> I have an array of filenames.
>
> I want to read through each of the files.
>
> I want to try and match a word at the beginning of the line, if the word is
> not matched, I want to display an error and stop processing.
>
> SO...
>
>
> foreach @array_of_files
> {
> unless (-r $_ && -w $_)
> {
> print"***Error : Cannot find file $_\n";
> }
> OPEN(FILE, $_) or die etc.......
> while (<FILE>)
> {
> /^\b$word\b/ && $wordfound++;
> }
> close (FILE);
> unless ($wordfound)
> {
> print"*** Error : word not found in file $_\n";
> }
> $wordfound = 0;
> }
> Oh, and if anyone can suggest any 'better' ways of doing the above, please
> let me know.
$/=undef; # slurp mode
for (@array_of_files) {
my @wordfound =();
print"***Error : Cannot find file $_\n" unless -r && -w;
open(FILE, $_) or die "$_:$!\n";
my $file_contents =<FILE>; # get all the file
@wordcount = ($file_contents =~/^\b($word)\b/g);
close (FILE);
print"Word found $#wordfound times in file $_\n";
}
--
Frank Booth - Consultant
Parasol Solutions Limited.
(www.parasolsolutions.com)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]