Hello All!
I canīt get my "top refferers" script to work, it simply
doesnt write to the file it should, it doesnt write at
all actually.. :(

Does anyone has any tip on what to change?

The script is pasted in below (it does exist of multiple
files, this is the part that doesnt work).

Would be really happy for any advice!! :)

AlexanderZ

This is the code I use:
#!/usr/bin/perl 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"); } 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); 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"); } &amp;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 { &amp;Get_Template; &amp;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] = $conte +nt[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"; } } #---------------------------------------

BazB: added code and readmore tags, hopefully removed all HTML and HTML encoding from code section.


In reply to perl cgi-bin script by AlexanderZ

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.