CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
search pattern not terminated

 



habel_k
New User

Jan 21, 2008, 11:49 AM

Post #1 of 4 (2945 views)
search pattern not terminated Can't Post

i am getting this error: search pattern not terminated...what could be the problem. I am trying to parse the apache access log:

eg of an entry:

10.25.95.100 ab - [05/Aug/2003:12:00:30 -0700] "GET /creative/2|2127274-1;iframe? HTTP/1.1" 200 791



My code:



#!/usr/bin/perl -w
use strict;

my $LOG_PATTERN = q{(.*) \- \[(.*)\] \"(.*) (.*)\?(.*) HTTP\/(.*)\" ([0-9]*) ([0-9]*)};

my $len = @ARGV;
if ($len <1){
print "Usage : perl script_name logfile\n";
exit();
}

if (!(-e $ARGV[0])){
print $ARGV[0]," : not exists.\n";
exit();
}

#Open log file for reading.

open (SEM, "< $ARGV[0]") or die "Cannot open file $ARGV[0]\n";
while (){

#We can also assign to a hash.

if (my($ip,$date,$method,$url,$query,$protocol,$retcode,$byte)=($_ =~ m/$LOG_PATTERN))
{ print "IP :",$ip,"\n";}
}
close(SEM);


KevinR
Veteran


Jan 21, 2008, 1:23 PM

Post #2 of 4 (2942 views)
Re: [habel_k] search pattern not terminated [In reply to] Can't Post

right here:

=~ m/$LOG_PATTERN)

see the problem? No trailing / at the end of the regexp.
-------------------------------------------------


habel_k
New User

Jan 21, 2008, 3:18 PM

Post #3 of 4 (2937 views)
Re: [KevinR] search pattern not terminated [In reply to] Can't Post

Thank you for the assistance,it will be great if you can clarify it a little more for me. I placed a trailing / and now i get the same error on a different line. The full code is as follows:



#!/usr/bin/perl -w
use strict;

my $s = '10.25.95.100 ab - [05/Aug/2003:12:00:30 -0700] "GET /creative/2|2127274-1;iframe? HTTP/1.1" 200 791 "-" "Mozilla/4.0(compatible; MSIE 5.5; Windows 98)""TC1=1067055_5565+067055+0+30fc+3fb5+20742d+1; PWH=m2w/./o0.Nyvo0/I..d/I./I.; Xc294&2127030&1=1059866137&13384&18337; Xc15&2127102&2=1060109088&13025&17516; Xc200&2127519&2=1060109135&13301&18215" "Imp: 294&18421&2127274&1&13384&1060110030" -';

my $LOG_PATTERN = q{(.*) \- \[(.*)\] \"(.*) (.*)\?(.*) HTTP\/(.*)\" ([0-9]*) ([0-9]*)};

print "\$s=$s\n";

my $var10='';

$s =~ /(.*) \- \[(.*)\] \"(.*) (.*)\?(.*) HTTP\/(.*)\" ([0-9]*) ([0-9]*) \"(.*)\" \"(.*)\"/;

print "Trick 1: \$1=$1, \$2=$2, \$3=$3, \$4=$4, \$5=$5, \$6=$6, \$7=$7, \$8=$8, \$9=$9, \n",

" \$\`=",$`," \$\'=",$',"\n";


my $len = @ARGV;
if ($len <1){
print "Usage : perl script_name logfile\n";
exit();
}

if (!(-e $ARGV[0])){
print $ARGV[0]," : not exists.\n";
exit();
}

open (SEM, "< $ARGV[0]") or die "Cannot open file $ARGV[0]\n";while ()
{
if (my($ip,$date,$method,$url,$query,$protocol,$retcode,$byte)=($_ =~ m/$LOG_PATTERN))
{ print "IP :",$ip,"\n";}
}
close(SEM);


KevinR
Veteran


Jan 22, 2008, 9:37 AM

Post #4 of 4 (2921 views)
Re: [habel_k] search pattern not terminated [In reply to] Can't Post

I don't know, I see the same error:


Code
 if (my($ip,$date,$method,$url,$query,$protocol,$retcode,$byte)=($_ =~ m/$LOG_PATTERN)) 
{ print "IP :",$ip,"\n";}


there is no '/' after $LOG_PATTERN in the above line.

fix that error.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives