Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Good programmers vs. Logs

Status
Not open for further replies.

steam

ISP
Jul 17, 2000
51
IT
I would like to write a routine for reading logs but it enters into a loop and the CPU is almost completely taken. Can you suggest something?

-------
open(UIL,"$logs");
@in=<UIL>;

foreach $on (@in){
split(/\|/,$on);
push(@a, $_[0]);
push(@b, $_[0]);}
foreach $c (@a){
$x=0;
foreach $y (@z){
if ($c eq $y){$k=$c;}}
if ($c ne $k){

foreach $d (@b){
if ($d eq $c){
push(@z,&quot;$d&quot;);$x++;}}}
if ($x >0){
open(T,&quot;>>report/log.rep&quot;);print T&quot;$x|$c|\n&quot;;}
}
open(T,&quot;report/log.rep&quot;);
@T=<T>;
foreach $l (@T){
@T1=split(/\|/,$l);
open (TMP2,&quot;file.html&quot;);
while (<TMP2>) {$_=~s/\[date\]/$T1[0]/g;$_=~s/\[calls\]/$T1[1]/g;
print $_;}
}

-------

This counts the no. of call per day ($_[0]) but when the log file is too big (i.e. 2Mb) it cannot generate the report. It seems a loop :(

I read the log file, then I push the dates into 2 arrays. Then I compare them: I count how many times the date is repeated. The results are printed in a report file (rep.log).

Sorry. This is the first time I make something like this ... on big files!

Here is an example of the original log file (the real file is around 2Mb):

-----
10/15/2000|hour|ip
10/15/2000|hour|ip
10/15/2000|hour|ip
11/15/2000|hour|ip
11/15/2000|hour|ip
11/15/2000|hour|ip
11/15/2000|hour|ip
----

The rep.log should be like this:

----
10/15/2000|3
11/15/2000|4
----




Thanks in advance.
[sig][/sig]
 
try

while(<>){
[tab]($date,$otherstuff) = split(/\|/);
[tab]$datesummary{$date}++;
}

then loop through the hash array ($datesummary that is) using keys and print out the counts [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>[/sig]
 
Thank you for your response. Ok I'll try it. ... wait ... how can I list/print $datesummary{$date}, foreach date found?

Thank you very much.
[sig][/sig]
 
foreach $key (keys %datesummary){
print &quot;key=$key, value= $datesummary{$key}\n&quot;;
} [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top