On 11/17/2006 01:22 AM, Gregory Machin wrote:


Hi

Hi Gregory Machin. You top-posted. Please don't do that. I corrected the
top-posing and made it a bottom-post.

I'm still not getting the result i require please could someone have a
quick look and see what i'm missing ...

the following code is suposed to break up the looked info from dns
server so I can manipulate  it.
It dies with the following errors when it reads more than one line
from the database ....

Can't call method "fetchrow" without a package or object reference at
./test.pl line 13.
<code>
#!/usr/bin/perl

use strict;
use warnings;
# Change your program to work with these.


#$test = "15-Nov-2006 14:11:06.304 update: info: client
196.211.85.42#35435: view external: updating zone
\'goal.lek.linserv.co.za/IN\': add
use Mysql;
$dbh = Mysql->connect('localhost','syslog_ng','root','')
 or die("Error " . $dbh->errno . " - " . $dbh->errstr);

Why would you invoke errno and errstr on an undefined value? $dbh has to be undefined if the die clause is being executed.

$query = $dbh->query("SELECT msg FROM logs where program = 'named'; ")
 or die("Error " . $dbh->errno . " - " . $dbh->errstr);
while (@row =  $query->fetchrow){

You use $query to get access to the query data--okay.

#chomp ;
#if ($test =~ /^(\d+)-(\w+)-(\d+) (\d+):(\d+):(\d+).*?client
(\d+)(.\d+)(.\d+)(.\d+)#(\d+): view external: (.*)$/){
$_ =~ tr/'//d ;
if ($row[msg] =~ /^(\d+)-(\w+)-(\d+) (\d+):(\d+):(\d+).*?client
(\d+)(.\d+)(.\d+)(.\d+)#(\d+): view external: updating zone (.*)$/){

What is "msg"? Shouldn't you be trying to access "$row[0]" ?

               $day = $1;
               $month = $2;
               $year = $3;
               $hour = $4;
               $minute = $5;
               $second = $6;
               $clientip = $7;
               $clientip .= $8;
               $clientip .= $9;
               $clientip .= $10;
               $port = $11;
               $query = $12;


You just clobbered your query variable. It was set to the return value of "$dbh->query(...)" earlier, but now it gets replaced with some text, and that makes it impossible to get any more information out of that query.

This is the reason for your error.


               print("day is $day\n");
               print("month is $month\n");
               print("year is $year\n");
               print("hour is $hour\n");
               print("minute is $minute\n");
               print("second is $second\n");
               print("clientip is $clientip\n");
               print("port is $port\n");
               print("query is $query\n");
               print("\n");

       }else{
                       print("malformed log entry: $_ \n");
       }

</code>

$test is a sample of the syntex.


I think you mean "syntax."

Please don't top-post, or I won't read any more of your messages. And please try to use correct English spelling and grammar.

This works:

use Mysql;
use strict;
use warnings;

my $regex = '^(\d+)-(\w+)-(\d+) (\d+):(\d+):(\d+).*?client'
. '\s(\d+)(.\d+)(.\d+)(.\d+)#(\d+): view external: (.*)$';

my $dbh = Mysql->connect('localhost','test','')
or die("Connect failed.");
my $search = $dbh->query('select msg from logfiles')
or die("Query failed: " . $dbh->errstr);

while (my @row = $search->fetchrow) {
    no strict 'vars';
    $row[0] =~ tr/'//d;
    if ($row[0] =~ /$regex/os) {
           $day = $1;
           $month = $2;
           $year = $3;
           $hour = $4;
           $minute = $5;
           $second = $6;
           $clientip = $7;
           $clientip .= $8;
           $clientip .= $9;
           $clientip .= $10;
           $port = $11;
           $query = $12;

           print("day is $day\n");
           print("month is $month\n");
           print("year is $year\n");
           print("hour is $hour\n");
           print("minute is $minute\n");
           print("second is $second\n");
           print("clientip is $clientip\n");
           print("port is $port\n");
           print("query is $query\n");
           print("\n");
    } else {
        print "Malformed Log Entry: $row[0]\n";
    }
}

undef $search;
undef $dbh;



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to