|
| =0D=0AFrom: John Doe <security.department@tele2.ch>
To: beginners@perl.org
Date: Thursday, March 31, 2005, 2:24:24 PM
Subject: apache log parsing
Thursday, March 31, 2005, 2:24:24 PM, you wrote:
> Am Donnerstag, 31. M=E4rz 2005 11.08 schrieb John:
[color=darkred]
> Always use "use strict; use warnings" in your code - it gives you very go=
od
> hints:
> use strict;=20
> use warnings;
> my $datetime=3D"DD/MM/YYYY:HH:MM:SS";
> @fields=3Dsplit(/[/:]/, $datetime);
> # This prints out:
> Global symbol "@fields" requires explicit package name at - line 3.
> Unmatched [ in regex; marked by <-- HERE in m/[ <-- HERE / at - line 3.
> Here is the modified code:
> use strict; use warnings;
> my $datetime=3D"DD/MM/YYYY:HH:MM:SS";
> my @fields1=3Dsplit(/[\/:]/, $datetime); # [1]
> my @fields2=3Dsplit(m,[/:],, $datetime); # [2]
> print join ", ", @fields1;
> print "\n";
> print join ", ", @fields2;
> # This prints out:
> DD, MM, YYYY, HH, MM, SS
> DD, MM, YYYY, HH, MM, SS
> To avoid perl interpreting a "/" searched for with the end of the regex, =
you
> either have to=20
> [1] escape "/" with " \"
> or=20
> [2] use another "delimiter" (don't know the english term at the moment) f=
or
> the match regex - in this case, "m,," instead of "//", explicitly indicat=
ing
> the match with an "m".
> see perldoc perlre
> joe
Yeah, it worked. Thanks a lot.
I found the a module Apache::Regexp can parse apache logs
but i am afraid it cannot output statistics just does what
i am trying to do subsrt the datetime, hosts, etc.
|
|