Hello Stephen,

I think the problem might be with your regular expression and not $x.

If your regular expression does not match the current line then every line
will be skipped.

What does the line that is being processed look like?

Dave

-----Original Message-----
From: Stephen Reese [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, 24 September 2008 3:10 PM
To: beginners@perl.org
Subject: regex count

I'm looking to increase the count $x every time a match is made for
the regex. Though I'm not having any luck nor am I receiving any
errors. I'm missing something, it seems $x++ would increase $x since
it starts at 0 by default?
http://www.doulos.com/knowhow/perl/quick_start/

my ( %srca );
my $x;

while (<LOG>) {
        next unless
/Sig:\s*(\d+)\s+Subsig:\s*(\d+)\s+Sev:\s*(\d+)([^\[]+)\[([\d\.]+):(\d+)\s*->
\s*([\d\.]+):(\d+)
/;
        $x++;
        print $x;
        $srca{ $5 } += $x;      
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to