hi,
Here is my Code as under:
The log files for this program are as under:
I have made log simple as under with my code:
In the code above i have put ??????? . There i am trying to match = and split them to store them into the database. I have used
Here is my Code as under:
Code:
#! /usr/bin/perl -w
use DBI;
my %hash;
my @arr;
my @arr1;
my @arr2;
my $var;
my $jn;
my $vari;
my @array;
my @array1;
my @array2;
my @array3;
#Variable Declaration
my $path = "D:/pavan/muco.log";
#definition of DataBase variables
my $db="ASP_WebStats";
my $host="192.168.0.2";
my $user="jivausers";
my $password="jivausers";
@arr1 = sub_loc();
print "------------------------------------------------------ \n";
print "@arr1 \n";
print "--------------------------------------------------------- \n";
my $count = scalar(@arr1);
#
#print "<$count> \n";
#print "($arr1[5])";
foreach(@arr1)
{
if($_=~/[\n,\s]/)
{
#print "<<$`>>\t<$'>\n";
push(@array1,$`,$');
}
#print "$_";
}
my $count1 = scalar(@array1);
for($i=0;$i<$count1;$i++)
{
my $join_var = join (" ",$array1[$i],$array1[++$i]);
# print "((($join_var))) \n";
push(@array2,$join_var);
}
# print "!!!$array2[0]!!!";
#my $dum = scalar(@array2);
foreach(@array2)
{
if($_=~/(\w)*(\s)*/)
{
#print "$'\n";
push(@array3,$');
}
else
{
print "The Pattern does not match the given string";
}
}
print "+++@array3+++\n";
foreach(@array3)
{ ?????????
}
print "\n\n\n\n";
#connect to MySQL database
my $dbh=DBI->connect ("DBI:mysql:database=$db:host=$host",
$user,
$password)
or die "Can't connect to database: $DBI::errstr\n";
$sth = $dbh->prepare("select * from Product order by Product_Id") or warn "Cannot Prepare: $DBI::errstr \n";
$sth->execute(); #Execute statement Handler
my $dump_reference = $sth->fetchall_arrayref;
foreach $dval (@$dump_reference)
{
print "---------------------------------------------------------------- \n";
print "Product ID: @$dval[0] \n";
print "Product Code: @$dval[1] \n";
print "Product Name: @$dval[2] \n";
print "Product Type: @$dval[3] \n";
print "Created By: @$dval[4] \n";
print "Created DTM: @$dval[5] \n";
print "Modified By: @$dval[6] \n";
print "Modified Dtm: @$dval[7] \n";
print "------------------------------------------------- \n";
@arr=();
}
sub sub_loc
{
@array=();
#open a filehandler in readmode
open(FH, "<$path");
while(<FH>) #loop through the entire contents of the file
{ # Open Brace of a while loop
#print "<$_>\n";
#if $_ contains 0 or multiple words followed by a single or multiple spaces followed by any of the characters below
if($_=~/(\w)*(\s)*[\{,\(,\-,\+,\=,\^,\!,\%,\<,\>,\?,\/,\&]/)
{
#print "$&";
#print ">>>>>$'<<<<<"; #prints the string after match
#print "$var \n";
$jn = join(" ",$&,$'); #Joins the matched part with the one after match with space
#print "(((((($jn))))))";
push(my @arr,$jn); # push the joined values in a list
# print "<@arr>";
#print "<<@arr>> \n";
foreach(@arr) #Loop through the entire list
{
if($_=~/[\",\(,\)]/) #If that list contains " or ( etc
{
$_=~ s/[",(,),},{]//g; #Removes them
# print "*************$_*************** \n\n";
push(@array,$_); #Pushes the _ contents in a list
} #close if
} #close foreach
} #close if
#return @array;
}
return (@array); #Returns the entire list
} #close sub
Code:
TURNAWAY (type="video" product="opiv" session="foo12345" customer="muco:1234" time="1234567890")
CUSTOMER {customer_id="muco:443" name="Yale University"}
PLAYBACK (type="audio" product="glmu" customer_id="muco:443" session="muco:foo12345abcde" user_id="muco:123" identifier="muco:123456" publisher="EMI" title="Merengue from Music of Guatemala, Vol. 1" played="180" timestamp="1234567890" token="abcdef1234567890abcdef")
HTTPLOG (format="apache" product="cpho" customer="123")
Code:
TURNAWAY type=video product=opiv session=foo12345 customer=muco:1234 time=1234567890 CUSTOMER customer_id=muco:443 name=Yale University PLAYBACK type=audio product=glmu customer_id=muco:443 session=muco:foo12345abcde user_id=muco:123 identifier=muco:123456 publisher=EMI title=Merengue from Music of Guatemala Vol. 1 played=180 timestamp=1234567890 token=abcdef1234567890abcdef HTTPLOG format=apache product=cpho customer=123
Code:
foreach(@array3)
{
if(s/\=/g)
{
print "$`";
print "$';
}
but only first '=' from a line is matching.\g is not working there. Can u plesase help me?
Thanks,
pavan
}
Comment