Thanks for that information about benchmarking, that is exactly what I needed. Btw, what I meant by "I don't trust it because it is too simple" is that it looked like too simple of a solution to what looked to be a complex problem, but really wasn't.

For those who still want to see the code, here it is (I've removed all of the stuff that doesn't have to do with the hierarchy part, to cut down on confusion):

#!/usr/bin/perl # *********************** # Name: hierarchy.pl # Author: Joe Ryan # Date Finished: August 10th, 2001 # Where Used: http://amherst.k12.oh.us/cgi-bin/weblog/hierarchy.pl # Description: An extension to mainlog.pl that lets the # user browse through the amherst website, showing the hits # per directory and per file. Note that the script # doesn't directly run off the weblog, but rather a text # file that is created after processing the weblog. open(DATA, 'pagehits.txt'); @mlines = <DATA>; close(DATA); $cutat = 2; # recursive function that prints the hierarchy sub print_hierarchy { my ($newlevelref, $newhitsref, $x, $stophere, $plvars, $temp, $tem +p1, $resume) = @_; my (@newlevel) = @$newlevelref; my (@newhits) = @$newhitsref; if ($x<=$cutlevelat) { print "<ul>\n"; $spaces = "<li>"; $spacesend = "</li>"; my ($y)=0; for ($y=0; $y < @newlevel; $y++) { my ($newleveltemp) = $newlevel[$y]; my ($newhitstemp) = $newhits[$y]; my ($temp2) = $temp.$newleveltemp; my ($temp3) = $temp1.$newleveltemp; my ($p_count) = ($newleveltemp =~ tr/\.//); if ($p_count < 1) {$temp2.="/"; $temp3.="/";} eval ("\$plvars1 = \$plvars\.\"&pathlevel".$x."=\$newlevel +temp\""); print "$spaces $newhitstemp&nbsp;<a href=\"$temp2\">$newle +veltemp</a>&nbsp;<a href=\"/cgi-bin/weblog/hierarchy.pl?&cutlevelat=" +.($x+1)."$plvars1\">></a>&nbsp;<a href=\"/cgi-bin/weblog/hierarchy.pl +?addwatch=$temp3&addhits=$newhitstemp&cutlevelat=".($x+1)."$plvars\"> ++</a>$spacesend\n" unless ($newleveltemp =~ /\./ || $newleveltemp eq +""); if ($y == $stophere) { eval ("print_hierarchy(\\\@newlevel".($x).", \\\@newhi +ts".($x).", ".($x+1).", \$stophere".($x+1).", \$plvars1, \$temp2, \$t +emp3, 1)"); } } print "$spaces<b>--------------</b>$spacesend\n"; for ($y=0; $y < @newlevel; $y++) { my($newleveltemp) = $newlevel[$y]; my($newhitstemp) = $newhits[$y]; my($temp2) = $temp.$newleveltemp; my($temp3) = $temp1.$newleveltemp; eval ("\$plvars1 = \$plvars\.\"&pathlevel1=\$newleveltemp\ +""); my($p_count) = ($newleveltemp =~ tr/\.//); if ($p_count < 1) {$temp2.="/"; $temp3.="/";} print "$spaces $newhitstemp <a href=\"$temp2\">$newlevelte +mp</a>"."&nbsp;<a href=\"/cgi-bin/weblog/hierarchy.pl?addwatch=$temp3 +&addhits=$newhitstemp&cutlevelat=0$plvars\">+</a>\n" if ($newleveltem +p =~ /\./ && $newleveltemp ne ""); } print "</ul>\n"; } else { return 1; } } use CGI; $query = CGI::new(); # $cutlevelat is how many levels out a directory is from the base $cutlevelat = $query->param("cutlevelat"); $cutlevelat=0 if (!$cutlevelat); for ($i=0; $i<$cutlevelat; $i++) { eval ("\$pathlevel".$i." = \$query->param(\"pathlevel".$i."\")"); } print "Content-type: text/html\n\n<html><head><title>Hierarchy View</t +itle></head><body bgcolor=\"#FFFFFF\">\n"; @mypath = (""); @myhits = (0); $y=0; $v=0; for ($i=0; $i<$cutlevelat; $i++) { eval("\$n".$i."=0"); } for($i=0; $i<@mlines; $i++) { @entry = split (' ', $mlines[$i]); @path = split (/\//, $entry[0]); $temp=""; $x=1; for (; $x<=$cutat;$x++) { $path1[$x-1]=$path[$x-1]; $temp.=$path[$x-1]; $temp.= "/"; } $breakcheck=1; for ($c=0; $c<$cutlevelat; $c++) { $breakcheck=1; eval("\$pathlevel=\$pathlevel".$c); if ($path[$#path1+$c] eq $pathlevel) { eval("\$meep=\@newlevel".$c); for($z=0; $z<$meep; $z++) { eval ("\$narf=\$newlevel".$c."[\$z]"); if ($path[$#path1+1+$c] eq $narf) { eval ("\$newhits".$c."[\$z]+=\$entry[1]"); $breakcheck=0; } } if ($breakcheck) { eval("\$newlevel".$c."[\$n".$c."] = \$path[\$\#path1+1 ++".$c."]"); eval("\$newhits".$c."[\$n".$c."] = \$entry[1]"); eval("\$n".$c."++"); } } } $entry[0]=$temp; $breakcheck=1; for($x=0; $x<@mypath; $x++) { if ($entry[0] eq $mypath[$x]) { $myhits[$x]+=$entry[1]; $breakcheck=0; } } if ($breakcheck) { $mypath[$t]=$entry[0]; $myhits[$t]=$entry[1]; $t++; } } @indices = (0 .. $#myhits); @sorted_indices = sort {$myhits[$b] <=> $myhits[$a]} @indices; @myhits = @myhits[@sorted_indices]; @mypath = @mypath[@sorted_indices]; for ($i=0; $i<$cutlevelat; $i++) { eval("\@indices = (0 .. \$\#newhits".$i.")"); eval("\@sorted_indices = sort {\$newhits".$i."[\$b] <=> \$newhits" +.$i."[\$a]} \@indices"); eval("\@newhits".$i." = \@newhits".$i."[\@sorted_indices]"); eval("\@newlevel".$i." = \@newlevel".$i."[\@sorted_indices]"); } # find where the next level of the hierarchy is supposed to go for ($i=0; $i<$cutlevelat-1; $i++) { eval ("\$stophere".($i+1)."=0"); eval ("\$meep=\@newlevel".$i); eval ("\$pathlevel=\$pathlevel".($i+1)); for ($x=0; $x<$meep; $x++) { eval ("\$narf=\$newlevel".($i)."[\$x]"); if ($narf eq $pathlevel) { eval ("\$stophere".($i+1)."=\$x"); } } } print "<h1>Individual Page Hits</h1>\n<table border=\"1\" cellpadding= +\"5\">\n"; for($i=0; $i<@mypath; $i++) { print "<tr><td>\n"; my (@path) = split (/\//, $mypath[$i]); print $myhits[$i]."&nbsp;"; print "<a href=\"http://www.amherst.k12.oh.us/\">Amherst Steele</a +>"; $temp = "http://www.amherst.k12.oh.us/"; $temp1 = "/"; if ($path[1] eq ""){$stop = 1;} $x=1; for ($x=1; $x < @path && $x < $cutat && $x != $stop; $x++) { print "&nbsp;>&nbsp;"; $temp .= $path[$x]; $temp1 .= $path[$x]; $p_count = ($path[$x] =~ tr/\.//); if ($p_count < 1) {$temp.="/"; $temp1.="/";} print "<a href=\"".$temp."\">".$path[$x]."</a>"; } $plvars = "&pathlevel0=$path[$#path]"; $endpath = $path[$#path]; if ($path[$#path] eq $pathlevel0) { print_hierarchy(\@newlevel0, \@newhits0, 1, $stophere1, $plvar +s, $temp, $temp1, $resume); } $p_count = ($endpath =~ /\.//); if ($p_count < 1) { print "&nbsp;<a href=\"/cgi-bin/weblog/hierarchy.pl?&cutlevela +t=1$plvars\">></a>&nbsp;"; } $stop=0; print "&nbsp;<a href=\"/cgi-bin/weblog/hierarchy.pl?addwatch=$temp +1&addhits=$myhits[$i]&cutat=$cutat\">+</a>"; print "\n</td></tr>\n"; } print "</table></body></html>";

I'm sure I can scope a lot of these variables a little better, and I'm sure that their are some more efficient ways to do some of the things I was doing (via a built-in function, etc.). If anyone sees anything at all to help sprouse it up, by all means tell me!


In reply to Re: Re: Question about benchmarking by jryan
in thread Question about benchmarking by jryan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.