http://www.perlmonks.org?node_id=318902

Alexx has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I am having troubles getting my top referer script to work, I bought it over a year ago and am now trying to set it up again.

Every time I run it it starts an endless loop, (the stderr file gets above 500 mb in filesize) and it does not write the information to the files as it is supposed to.

The script is supposed to read its self generated log and write the information into nice predefined formatted tables in html code. If anyone has any idea why this might happen IŽd be appreciative for some help.

Regards, Alexander

pasted script comes here:

#!/usr/bin/perl -w BEGIN { open(STDERR,">/usr/home/hsphere/local/home/snurk/snurk.net/cgi-bin/ +referer/error.txt"); chmod(oct(777)," /usr/home/hsphere/local/home/snurk/snurk.net/cgi-b +in/referer/error.txt"); } ###################################################### # Referer.cgi Version 1.10 # # This script is written by # # Frank Larsen 2000 # # http://www.bozysweb.com # ###################################################### require 'settings.conf'; require 'exclude.conf'; require 'include.conf'; $data = ""; $template_file = "template.txt"; @html_file = @pages; print "Content-type: text/html\n\n"; print "Updating the HTML file(s)<br>\n"; print "Please Hold\n"; $|=1; $time = time(); if ($uniqe eq '1') { open(SESAME,"$referer_log.backup") || die "Could not open Referer Log" +; @filecontents = <SESAME>; close(SESAME); @hash{@filecontents}=(); @filecontents=keys %hash; open(SESAME,">$referer_log.backup") || die "Could not open Referer Log +"; foreach $line(@filecontents){ print SESAME "$line";} close(SESAME); chmod (0666, "$referer_log.backup"); } print("just opened log backup file"); open(LOG,"$referer_log.backup") || die "Could not open Referer Log"; while(<LOG>){ $ref = $_; foreach$skip(@skip_pages) { if($ref =~ /$skip/) { $bad =1; } } if(!$bad) { ($test,$testbogus) = split(/\|/,$ref); study($test); $test =~ s/:80//g; $test =~ s/%7E/~/g; $sitecount ="0"; foreach $line(@siteurl) { if($test =~ /$line/) { $test = "$sitedesc[$sitecount]"; $test .= "||$sitename[$sitecount]"; } $sitecount++; } $HASH{"$test"}++; $grandtotal++; } undef($bad); print ".\n"; } close(LOG); print("just closed the logfile"); sub bynumber { $b <=> $a; } foreach$key(keys %HASH) { $line = "$HASH{$key}\::$key"; push(@array,$line); } undef(%HASH); @array = sort bynumber @array; $time = time() - $time; open(SESAME,"header.txt"); @filecontents = <SESAME>; close(SESAME); foreach $line(@filecontents) { $line =~ s/\"/\"/; $line =~ s/\#/\#/; $line =~ s/\?/\?/; $header .= "$line"; } open(SESAME,"footer.txt"); @filecontents = <SESAME>; close(SESAME); foreach $line(@filecontents) { $line =~ s/\"/\"/; $line =~ s/\#/\#/; $line =~ s/\?/\?/; $footer .= "$line"; } $antal ="0"; $rank ="1"; while ($antal < $top) { $part = $array[$antal]; ($total,$referer) = split(/::/,$part); if($total >= $minumum_referals) { if($referer !~ /^http:\/\//){ $data = "$rank"; $data .= "||$referer"; $data .= "||$total"; } else { $data = "$rank"; $data .= "||$referer"; $data .= "||$total"; } push(@Ref_Info,"$data"); } $antal++; $rank++; } if ($userunners eq "1"){ $tempup = "||$runnersurl||Runners Up||?"; push(@Ref_Info,"$tempup"); } &preview; if ($userunners eq "1"){ $runnersrank = ($#Ref_Info + 1); open(FH,">$runnerspath"); print FH "<html><head><title>Runners Up</title></head>\n"; print FH "<body bgcolor=#000000 text=#ffffff>\n"; print FH "<p align=center><b>Runners Up</p>\n"; print FH "<p align=left>\n"; do {print FH "<li>$array[$runnersrank]\n"; $runnersrank++; } until ($runnersrank > $#array); print FH "</p></body></html>\n"; close(FH); } print "<br>File(s) updated<br>You may close this window now..\n"; exit; #__________________________________________________________________ sub preview { &Get_Template; &Get_New_Links; foreach $pages(@html_file){ open(SESAME,"$pages"); @Old_HTML = <SESAME>; close(SESAME); @New_HTML = (""); do { $temp = shift(@Old_HTML); push(@New_HTML,"$temp"); } until ($temp =~ /<!-START->/); push(@New_HTML,"$header"); push(@New_HTML,@NewLines); do { $temp = shift(@Old_HTML); } until ($temp =~ /<!-END->/); push(@New_HTML,"$footer"); push(@New_HTML,"$temp"); push(@New_HTML,@Old_HTML); chmod (0666,$pages); open(SESAME,">$pages"); print SESAME "@New_HTML"; close(SESAME); chmod (0644,$pages); } } #------------------------------ sub Get_HTML { open(SESAME,"$html_file"); @Old_HTML = <SESAME>; close(SESAME); } #-------------------------------- sub Get_New_Links { foreach $line(@Ref_Info){ @content = split(/\|\|/,"$line"); $rank = $content[0]; if ($content[3] eq ""){$content[3] = $content[2]; $content[2] = $c +ontent[1];} $referer = "<a href=\"$content[1]\" target=\"$target\">$content[2] +</a>"; $total = $content[3]; $temp = $template; $temp =~ s/<RANK>/$rank/g; $temp =~ s/<REFERER>/$referer/g; $temp =~ s/<TOTAL>/$total/g; $temp .= "\n"; push(@NewLines,"$temp"); } } #---------------------------------- sub Get_Template { open(SESAME,"$template_file"); @temptemplate = <SESAME>; close(SESAME); foreach $line(@temptemplate){ $template .= "$line"; } } #---------------------------------------

Replies are listed 'Best First'.
Re: CGI script loop
by ysth (Canon) on Jan 05, 2004 at 18:58 UTC
    Out of curiousity, what is the script supposed to do? And what is in the 500Mb error log?

    <non-constructive-criticism>There are some quite amusing things there. $#Ref_Info + 1?? And quite a mixture of meaningful ($grandtotal), meaningless (%HASH), and confusing ($antal??) variable names. I wonder if the author benchmarked it with and without the study(). And the comments are great: dashes and underscores only! (except for the author information). </non-constructive-criticism>

    If you bought it, is support available? It's odd that it doesn't have a copyright statement.

    Update: better and better; $grandtotal is incremented but never used :)

      Top Referrer scripts are meant to generate link trades. The idea goes something like this:
      1. You and 9 of your friends agree to put each other's banners up on your sites. But, there's a catch - you don't want to link to chromatic and potentially give him business unless his site is generating business for you.
      2. So, you only actually display one of your friends's banners. Which one is determined by how much business each friend has done for you.
      3. You keep track and, let's say chromatic has sent you 40%, tilly 40%, but jeffa's site never sends you any business. So, you display each person's banner according to the amount of business they've sent you.

      The calculations can get arbitrarily complex. There are even sites that keep track of this stuff for you and your friends. (I've done some work for one of those, which is why I've even heard of this. And, yes, it's that industry that is the primary, secondary, and pretty much only user for this technology.)

      ------
      We are the carpenters and bricklayers of the Information Age.

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: CGI script loop
by chromatic (Archbishop) on Jan 05, 2004 at 18:53 UTC

    What does the error log say?

Re: CGI script loop
by !1 (Hermit) on Jan 05, 2004 at 20:26 UTC

    Considering you purchased this script, I'm curious whether or not you can post the script without the author's permission?

    Update: I seem to assume too much and as such the idea I wish to present is nowhere to be found within the contents of this post. Please refer to CountZero's reply below.

      Well, if you have bought it (rather than obtained a license for it, which is probably more likely), its yours and you can pretty well do what you like with it.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        Quite right. Thank you for pouncing upon my mistake and so skillfully correcting me.

        I've decided not to post again until I can learn to clearly convey what I mean in my posts. Again, thank you.