On Thu, Aug 09, 2001 at 08:35:42PM -0500, Tyler Longren wrote:
: Hello everyone,
: 
: I have a string from an apache log file:
: 192.168.1.1 - - [05/Jul/2001:22:48:51 -0500] "GET /test.php HTTP/1.1" 
: 200 995
: How could I get the IP (192.168.1.1) out of that?  I've been playing 
: with regexps like this:
: if/(.*)\s-\s-\s/;
: 
: but I have no idea if that's correct or not.  Can anybody offer any 
: help?

I'm going to pretend that I have the log line above in the variable
named $log_line:

You could use a regex:

  $log_line =~ /([\d.]+)\s/;
  my $ip_addr = $1;

 The short version:

  my( $ip_addr ) = ( $log_line =~ /([\d.]+)\s/ );

You could *not* use a regex:

  my @line    = split /\s+/, $log_line;
  my $ip_addr = shift( @line );

I would probably just use the split() version.  

  Casey West

-- 
Shooting yourself in the foot with Cray
You shoot yourself in the foot with an Uzi.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to