AlexanderZ has asked for the wisdom of the Perl Monks concerning the following question:
#!/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"); } &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] = $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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl cgi-bin script
by davido (Cardinal) on Nov 15, 2003 at 05:23 UTC | |
|
Re: perl cgi-bin script
by sgifford (Prior) on Nov 15, 2003 at 08:50 UTC | |
|
Re: perl cgi-bin script
by Roger (Parson) on Nov 15, 2003 at 00:56 UTC | |
by BUU (Prior) on Nov 15, 2003 at 04:07 UTC | |
|
Re: perl cgi-bin script
by Anonymous Monk on Nov 16, 2003 at 01:01 UTC |