M�rcio Oliveira wrote:
> Hi all.
>
> I have a simple (I guess) question about spliting strings in perl.
>
> I need to split a string like this: "10.10.2.131 - -
> [27/Jul/2004:08:20:43 -0300] "GET http://lalala/chiclete_01.jpg
> HTTP/1.0" 407 1399 TCP_DENIED:NONE" (a squid log) in some parts:
>
> $ip = 10.10.1.131
> $date = [27/Jul/2004:08:20:43 -0300]
> $url_info = http://lalala/chiclete_01.jpg
> $state = TCP_DENIED:NONE
>
> How i can extract this parts from a var eq that string?
> This is the script I use to read the file and get the string ($linha)
> one per line:
>
> #!/usr/bin/perl
> use strict;
>
> my ($linha);
>
> open (FILE,"<access.log");
>
> while ( defined ($linha = <FILE>) ) {
> chomp $linha;
>
> #???? what i can use ?
Simple way to do it:
my @parts = split ' ', $_;
@parts will then contain :
10.10.2.131
-
-
[27/Jul/2004:08:20:43
-0300]
"GET
http://lalala/chiclete_01.jpg
HTTP/1.0"
407
1399
TCP_DENIED:NONE
and you can use whichever fields you want from it. 3 and 4
would need to be re-concatenated for the date field, but it's
the simplest way to split it. eg: $date = "$parts[3] $parts[4]";
Or you can use your own names on the split :
my ($ip, $x1, $x2, $date1, $date2, $x5, $url_info, $x7, $x8, $9, $state) =
split ' ';
> }
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs