Mumia W. wrote:
> 
> 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: (.*)$';

You need to escape the . character to match a literal period.  You should
probably also use the qr// operator:

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


> 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';

Why are you turning off strict?

>     $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");

Why all the copying?

    if ( $row[ 0 ] =~ /$regex/ ) {
           print <<TEXT;
day is $1
month is $2
year is $3
hour is $4
minute is $5
second is $6
clientip is $7
port is $8
query is $9

TEXT

>     } else {
>         print "Malformed Log Entry: $row[0]\n";
>     }
> }
> 
> undef $search;
> undef $dbh;



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
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