#!/usr/local/bin/perl

$file = 'C:\Users\asdds\test1.log';
open(INFO, $file);
@lines = <INFO>;
foreach $data (@lines)
{
 chomp($data);
 (@x,@y)=split( ,$data);




 print "@x[0]\n";
 print "@y[0]\n";








}

 $length_ice = length (@x[0]);


print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<title>Server Log File Information</title>\n";
print "</head>\n";
print "<body>  Length of Total number of entries: $length_ice\n";
close(INFO);

i want to separate the following log file to x y z b how to do that im really confused.


wwwic.ndsu.edu - - [21/Jun/2000:20:21:36 -0400] "GET / HTTP/1.1" 200 1786
wwwic.ndsu.edu - - [21/Jun/2000:20:21:37 -0400] "GET /slator/classes/hci/Home/home3/home3.html HTTP/1.1" 200 3734
wwwic.ndsu.edu - - [21/Jun/2000:20:21:37 -0400] "GET /slator/classes/hci/Home/home3/img3.gif HTTP/1.1" 200 167
wwwic.ndsu.edu - - [21/Jun/2000:20:21:38 -0400] "GET /slator/classes/hci/Home/home3/home3.css HTTP/1.1" 200 714
bison.fans.com - - [21/Jun/2000:20:22:30 -0400] "GET /~magel/classes/csci713/Transforms/wtov/wtov.html HTTP/1.0" 302 277
bison.fans.com - - [21/Jun/2000:20:22:33 -0400] "GET /magel/classes/csci713/Transforms/wtov/wtov.html HTTP/1.0" 200 27973
researchpark-ubr-c3-198.cfl.rr.com - - [21/Jun/2000:20:23:32 -0400] "GET /man/java.tar HTTP/1.1" 200 10768868
bison.fans.com - - [21/Jun/2000:20:24:11 -0400] "GET /~jli/classes/ds.html HTTP/1.0" 200 1175
j3012.edutech.com - - [21/Jun/2000:20:24:58 -0400] "GET /magel/classes/csci718/Texture/bump/bump.css HTTP/1.0" 200 344
j3019.edutech.com - - [21/Jun/2000:20:28:04 -0400] "GET /magel/catalog98/catalog/node9.html HTTP/1.0" 200 43476
j3005.edutech.com - - [21/Jun/2000:20:29:06 -0400] "GET /~king/ada/programs/invert/invert.ads HTTP/1.0" 200 150
nat-wv.mentorg.com - - [21/Jun/2000:20:29:42 -0400] "GET /~king/java/programs/quit/Beep-java.html HTTP/1.0" 200 4765
208.162.150.248 - - [21/Jun/2000:20:33:10 -0400] "GET /~king/ada/language/declaration-bnf.gif HTTP/1.0" 200 404589
208.162.150.248 - - [21/Jun/2000:20:33:10 -0400] "GET /~king/cd/csci717/final.html HTTP/1.0" 200 11178
wm3020.edutech.com - - [21/Jun/2000:20:35:53 -0400] "GET /magel/catalog00/catalog/node156.html HTTP/1.0" 200 2482
px1cl.gv.wave.shaw.ca - - [21/Jun/2000:20:37:38 -0400] "GET /~morris/c5083.html HTTP/1.0" 200 26614
px3cl.gv.wave.shaw.ca - - [21/Jun/2000:20:37:38 -0400] "GET /pic/construction.gif HTTP/1.0" 200 236
m198214191245.austin.cc.tx.us - - [21/Jun/2000:20:38:39 -0400] "GET /pic/dotlogo.gif HTTP/1.1" 200 2965
m198214191245.austin.cc.tx.us - - [21/Jun/2000:20:38:39 -0400] "GET /pic/new.gif HTTP/1.1" 200 116
m198214191245.austin.cc.tx.us - - [21/Jun/2000:20:38:53 -0400] "GET /academic/grad-prog.html HTTP/1.1" 200 3135
m198214191245.austin.cc.tx.us - - [21/Jun/2000:20:39:13 -0400] "GET /~jli/dept/ms-cis-guide.html HTTP/1.1" 200 3505
165.138.48.12 - - [21/Jun/2000:20:38:58 -0400] "GET /magel/classes/csci716/fall96/fall96.css HTTP/1.0" 200 344
165.138.48.12 - - [21/Jun/2000:20:38:58 -0400] "GET /pic/cslogo.gif HTTP/1.0" 200 3223
71.64.35.65.cfl.rr.com - - [06/Mar/2001:17:05:43 -0500] "GET /magel/comps/exams/mathsp01.pdf HTTP/1.1" 206 -

Okay, well first, what part of each line of $file is 'x,y,z,b' supposed to be?

(@x,@y)=split( ,$data);

indicates you're trying to split it at spaces. But there are 9 spaces in each line and you're only capturing the first two splits and

@x,@y

is going to be over-written in each 'foreach'.

Then with

#
print "@x[0]\n";
#
print "@y[0]\n";

there are no file handles to print to so those will print to the command screen, assuming it's open - which it probably isn't since you're creating a html page later on.

Try

my $count = 0;
my @x = ();
my @y = ();
my @z = ();
my @b = ();
foreach my $data (@lines) {
    ($a_0,$a_1,$a_2,$a_3,$a_4,$a_5,$a_6,$a_7,$a_8)=split( ,$data);
    $x[$count] = $a_0;
    $y[$count] = $a_1;
    $z[$count] = $a_2;
    $b[$count] = $a_3;
    $count++;
}

Once you know how things are splitting up and how you need to recombine them, then you can concatenate or join the $a_0s and $a_1s or whatever into your 4 arrays. You also want to 'use strict' - it's good form.

This article has been dead for over six months. Start a new discussion instead.