in reply to Opening file and checking for data

To count multiple matches in a line, you can realize that m//g returns the matches in array context. That means that you can just say $counter += () = /patternmatchinghere/gi; for the counting.

I doubt if your error log is appended to your script after __END__ or __DATA__, so you should avoid the *DATA handle.

My rewrite:

my $counter = 0; open LOG, "< $errlog" or die 'Can not open: ', $!; $counter += () = /patternmatchinghere/gi while <LOG>; close LOG;
I've omitted opening $errlog to append, since I don't see what it does for you in this snippet.

Update: changed for to while to avoid slurping.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Opening file and checking for data
by Anonymous Monk on Jul 03, 2003 at 14:59 UTC
    Thanks for all the replies.