2 Replies - 2766 Views - Last Post: 23 October 2005 - 01:50 PM

#1 wingz198   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 14-October 05

Regular Expression Errors

Posted 22 October 2005 - 12:50 PM

I'm trying to write a program that processes a web log file. Here's an antry example:
3236 "GET /robert/./index.php?page=links HTTP/1.1" "30/Sep/2005:11:11:38 -0400" "Java/1.4.1_05" "-" - - 200 69.177.179.241


I made a regex to get the important parts:
$entry =~ /\
                   (\d+)\s+                        #bytes
                   (".*")\s+               #method.url.hvers
                   (".*")\s+               #date & time
                   (".*")\s+               #useragent
                   (".*")\s+               #referer
                   .*\s+.*\s+
                   (\d+)\s+                #statuscode
                   (.*)                    #ipaddy
                   /x;
             $bytes = $1;
             print $bytes;


I get an error
Use of uninitialized value in print at ./prog11.pl line 54 (#1)
    (W uninitialized) An undefined value was used as if it were already
    defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
    To suppress this warning assign a defined value to your variables.

when I try to print it out. Is there something wrong with the expression? The way I see it, it should work

This post has been edited by wingz198: 24 October 2005 - 08:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Regular Expression Errors

#2 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Regular Expression Errors

Posted 22 October 2005 - 01:35 PM

It looks as if you are assigning the variable butes tha value in the variable $1, but I do not see where you have defined that second variable. Is there more code that you have not shown?
Was This Post Helpful? 0
  • +
  • -

#3 wingz198   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 14-October 05

Re: Regular Expression Errors

Posted 23 October 2005 - 01:50 PM

I'm not sure what you mean.
Here's most of the code I have right now:
#If command line argument is not given, exit the program
if (!$ARGV[0])
{
        &usage();
}

my $logfile;
my @lines;
my $entry;
my $date; my $time; my $ipaddy; my $url; my $useragent; my $referer;
my $statuscode; my $bytes;

while ($logfile = shift)
{
        open (LOG, $logfile);
        @lines = <LOG>;
        close LOG;

        foreach $entry (@lines)
        {
                $entry =~ /\
                        (\d+)\s+             #bytes
                        (".*")\s+             #method.url.hvers
                        (".*")\s+             #date & time
                        (".*")\s+             #useragent
                        (".*")\s+             #referer
                        .*\s+.*\s+
                        (\d+)\s+             #statuscode
                        (.*)                    #ipaddy
                        /x;
                $bytes = $1;
                $url = $2;
                $date = $3;
                $useragent = $4;
                $referer = $5;
                $statuscode = $6;
                $ipaddy = $7;
                print $bytes;
        #       print $entry;
        }
}


I'm just trying to print hte $bytes var at the moment to check if I got it right.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1