Thanks a million! It works great, just as I wanted!

~Mike

> -----Original Message-----
> From: Aaron Trevena [mailto:[EMAIL PROTECTED]] 
> Sent: den 23 maj 2002 12:20
> To: [EMAIL PROTECTED]
> Subject: RE: Optional patternmatching?
> 
> 
> >     if ( m/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})   # IP Address
> >          \x20(.+?)                        # User
> >          \x20(.+?)                        # unused
> >          \x20(\[.+\])                     # Date
> >          \x20\"(.*?\n*?.*?)               # Request
> >          (HTTP\/.*?|)\"                   # Match regardless of HTTP
> > Version.
> >          \x20(\d+?)                       # Statuscodes
> >          \x20([\-\d]+?)                   # Size
> >          \x20(\".*?\")                    # Optional Referer
> >          \x20(\".*?\")                    # Optinal Browser type
> >          /ox )
> >
> > However, it's the last two fields ($9 and $10) that I want to be 
> > optional. If they don't exist in the current line being matched, I 
> > still want the rest of the fields to be populated ($1 - 
> $8). I.e. an 
> > 'optional' match...
> 
> (?:\x20(optionalstuffhere))? for the last two should do the 
> job as ? means match 1 or 0 times,  or you could even do 
> (?:\x20(\".*?\")){0,2} which matches a minimum of 0 and max 
> of 2 times making for a shorter regex.
> 
> for even more flexibility and ease you could use $patternA or 
> $patternB in your pattern such as $pattern = ($foo_is_true) ? 
> qw(pattern goes here) : qw(different pattern
> here) ;
> /$pattern/;
> 
> Its worth noting that there are several apache and other log 
> parsing modules on CPAN - perl has been used to parse Apache 
> logs since the year dot!
> 
> hope that helps,
> 
> A.
> 
> --
> Aaron J Trevena, BSc (Hons)     www.head2head.co.uk
> Internet Application Developer  Perl, UNIX, IIS/ASP
> 
> 
> _______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> 
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to