hi,
Here is my Code as under: -
#! /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
-
The log files for this program are as under: -
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")
I have made log simple as under with my 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
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 -
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
-
}
-
4 1553
try removing the "s":
like this:
the "s" is telling perl you want to do a substitution, and the code should throw an error because it is not a properly constructed regexp (s/pattern/substitution/).
Removing the "s" defaults it to a matching regexp (m/pattern/);
- open FH,"<test.txt";
-
while(<FH>)
-
{
-
my $data = $_; #Assigning line to the variable $data
-
print "$data\n";
-
while((length($data)) != 1) #unless $data is not equal to ) or } or ] or etc......
-
{
-
if($data =~ /(\w*)\=\"/) #matching word="
-
{
-
my $dt = $'; #Assigning After matched to $dt
-
$key = $1;
-
print "$key="; #printing the key
-
if($dt =~ /\"/) #Matching end of a value with "
-
{
-
print "$`\n"; #printing the value
-
# $value=$`;
-
# $sth = $dbh->prepare("select * from product where product_code='$value'");
-
# $resp = $sth->execute();
-
# if($resp ne '0E0')
-
# {
-
# $sth1 = $dbh->do("insert into sometable values('$value')");
-
# }
-
$data = $'; #Assigning the after matched to $data
-
$data =~ s/^\s//; #Removing first space
-
chomp($data); #Removing newline character of $data
-
}
-
}
-
}
-
print "\n";
-
}
-
close(FH);
-
-
my %hash = ();
-
open FH,"<test.txt";
-
while(<FH>)
-
{
-
my $data = $_; #Assigning line to the variable $data
-
print "$data\n";
-
if($data =~ /^(\w*)/) #To get first word of line
-
{ print "$1\n";$main = $1; }
-
while((length($data)) != 1) #unless $data is not equal to ) or } or ] or etc......
-
{
-
if($data =~ /(\w*)\=\"/) #matching word="
-
{
-
my $dt = $'; #Assigning After matched to $dt
-
$key = $1;
-
print "$key="; #printing the key
-
if($dt =~ /\"/) #Matching end of a value with "
-
{
-
print "$`\n"; #printing the value
-
$hash{$main}{$key} = $`; #Building hashes of hashes
-
# $value=$`;
-
# $sth = $dbh->prepare("select * from product where product_code='$value'");
-
# $resp = $sth->execute();
-
# if($resp ne '0E0')
-
# {
-
# $sth1 = $dbh->do("insert into sometable values('$value')");
-
# }
-
$data = $'; #Assigning the after matched to $data
-
$data =~ s/^\s//; #Removing first space
-
chomp($data); #Removing newline character of $data
-
}
-
}
-
}
-
print "\n";
-
}
-
close(FH);
-
#printing the hash
-
foreach$s(keys %hash)
-
{
-
print "$s\n";
-
foreach(keys %{$hash{$s}})
-
{
-
print "\t$_ <> $hash{$s}{$_}\n";
-
}
-
print "\n";
-
}
-
sasimca007,
I don't know about anyone else, but a whole lot of code, without any explanation is not the best kind of help. It would be better to point out where the OP has errors and such in there code instead of just freely providing them a solution to their problem.
The idea is for those asking questions to learn and by just giving them every answer freely does not always do that. Please don't get me wrong, thank you very much for helping and providing a solution, but be sure to help the OP learn and understand rather than just feeding them code.
Regards,
Jeff
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Thomas Reichelt |
last post by:
Moin,
short question: is there any language combining the syntax, flexibility and
great programming experience of Python with static typing? Is there a
project to add static typing to Python?
...
|
by: Simone Mehta |
last post by:
hi All,
I am parsing a CSV file.
I want to read every row into a char array of reasonable size and then
extract strings from it.
<snippet>
char foo="hello,world,bye,bye,world";
........
|
by: olaufr |
last post by:
Hi,
I'd need to perform simple pattern matching within a string using a
list of possible patterns. For example, I want to know if the substring
starting at position n matches any of the string I...
|
by: solarin |
last post by:
Hi,
I've developed a program under VS 6.0. I can compile it and run it, but
when I try to debbug , all my breakpoints are dissabled and I can see
the following messages:
Loaded...
|
by: abctech |
last post by:
My requirement is such that any user must not be allowed to save the same record twice.
For this what I do is as soon as some user fills up the page and clicks 'Save' I invoke a Servlet which...
|
by: cviniciusm |
last post by:
Hello,
I'm using "g++ (GCC) 4.1.1 20070105 (Red Hat 4.1.1-51)".
I'm trying to use the open() function as defined by the header
fcntl.h, but I'm getting this error:
"
mylibrary.cpp:16: error:...
|
by: santhoshs |
last post by:
Hello
I am required to parse two files that contain email addresses and figure out a way to get the matching and non-matching email addresses from both the files. I was able to get the matching...
|
by: tech |
last post by:
Hi, I need a function to specify a match pattern including using
wildcard characters as below
to find chars in a std::string.
The match pattern can contain the wildcard characters "*" and "?",...
|
by: sora |
last post by:
Hi,
I've developed a MFC program under VS 6.0. My debugger *was* working fine and I've used it often for my project. Then, one day, the errors below appear and they prevent me from using the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |