perlquestion
Anonymous Monk
Hi monks,<br>
I ask this question before, but I guess I wasn't clear about what I wanted to ask.<br>
All started when I needed to parse a log file that looks like that:<br>
<code>
Company Name*345467*YW34567c*activitype*04/15/2004*11:34:10*123456789*1
Company Name Other*345467*YW34567c*activitype*04/15/2004*11:34:10*123456789*3
</code>
<br>
Course many more lines will be there.<br>
I am tring to parse the log files here and running into problems where I can't display the name of the element I am looping trough, but I can print the number of times it shows on the file.
Here is the code, let me know please, where the problem is.
<br>
<code>
foreach (<LOGFILE>){
if (/^(.*?)*(.*?)*(.*?)*(.*?)*(.*?)*(.*?)*(.*?)*(.*?)$/gi){ #prin
+t starting at the date
push (@logg,$1); }
}
my %count;
my $total_count;
foreach my $element( @logg ) { #4
++$count{$element};
$total_count++;
}
#Sort hash by its values
foreach my $element (sort {$count{$a} <=> $count{$b}} keys %count){
print "Name: $element<font color=red size=\"2\">Shows:<b>$count
+{$element}</b></font> times.<br>";
}
</code>
<br>
I want to do this to every element on the file, I mean:<br>
$1*$2*...*$8. And display how many times each element was present on the file.<br>
If I run this code it will show the number of times ok, but I can't display such:<br>
Company was here for 8 times.<br>
I hope I was clear now.<br>
And,
Thanks for the help, once again!
<!-- edited by turnstep, changed title from "Regular Exp. Problem!" -->
7