in reply to question about regex and using a scalar variable to store/call it
you can store a regex string in a variable as so$regex = qr/(test)foo/i; #then to use it $var =~ $regex;
now, the first way is much better usually, especially if you use that pattern more than once, since it only has to compile once.$regex = '(test)foo'; #but then to call it you must do $var =~ /$regex/;
I would do...
now if your third arg is iis, it will parse iis logs, otherwise it will do apache... that help? Of course, it would not be a bad idea to use strict, either...#!/usr/bin/perl -w $log=qr/(.*)\s+-\s+-\s+\[(\d+)\/(\w+)\/(\d+):(\d+):(\d+)/; $log=qr/(\d+):(\d+):(\d+)\s+(\d+\.\d+\.\d+\.\d+)\s/ if $ARGV[2] eq 'ii +s'; $document=qr/report.html\?/; $document2=qr/secret.html\?/; # open the log file - the log file we want to check out open(LOG, "<$ARGV[0]") || die("Could not open $ARGV[0] : $!"); # open our Report file - the file we will write out report to open(REPORT, ">$ARGV[1]") || die("Could not open $ARGV[1] : $!"); while(<LOG>){ if($_ =~ $document){ ($ip, $day, $month, $year, $hr, $min) = ($_ =~ $log); $totaldoc++; print REPORT "Access on doc1 from: $ip on $month $day at $hr:$ +min\n"; } elsif($document2){ $totaldoc2++; print REPORT "Access on doc2 from: $ip on $month $day at $hr:$ +min\n"; } } print REPORT "Total doc1: $totaldoc\n"; print REPORT "Total doc2: $totaldoc2\n"; close(LOG); close(REPORT);
- Ant
- Some of my best work - Fish Dinner
|
|---|