CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Hit counter sort

 



IvarForss
Deleted

Apr 13, 2000, 1:24 PM

Post #1 of 4 (473 views)
Hit counter sort Can't Post

I started making my first program in perl, a hit counter...

anyway. it stores the hit on every page and stores it in a file. (http://i.am/bokhyllan/index.htm=40&http://i.am/bokhyllan/photos.htm=23&http://i.am/bokhyllan/me.htm=30&)

Now to the problem. I want to display the hits at a page with the page that scores highest at the top...

I split the urls and the values in different fields...

I tried to use the sort command to sort it but coulden figure out how to do it.


can anyone help me?!?


darian
Deleted

Apr 14, 2000, 2:19 AM

Post #2 of 4 (473 views)
Re: Hit counter sort [In reply to] Can't Post

Can you post your code so we can see how you used the sort function?


IvarForss
Deleted

Apr 15, 2000, 2:16 AM

Post #3 of 4 (473 views)
Re: Hit counter sort [In reply to] Can't Post

Her's the code.... but i dident figure out at all how to use the sort command so it isent included...

# Open counter file
open(File, "+<count.dat") &#0124; &#0124; die "can't update somewhere: $!";

$buffer = <File>; # read the line
seek(File, 0, 0); # go back to start of file for rewriting

#if (length ($ENV{'QUERY_STRING'}) > 0){
$page = $ENV{'QUERY_STRING'};
$page = "http://i.am/bokhyllan/3.htm"; # DEBUG
@pairs = split(/&/, <File> );
seek(File, 0, 0); # go back to start of file for rewriting
foreach $pair (@pairs){
($name, $value) = split(/=/, $pair);
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$in{$name} = $value;
if ($page eq $name) { $value = $value +1; $pagefound="yes"}
print $name,"=",$value, "\n";
push (@list, $name, "=", $value, "&");
}
print File @list;

if ($pagefound eq "yes") {
close File;
} else{
print File $page, "=1&";
print $page, " = 1 new!";
close File;
}
#}



Cure
User

Apr 15, 2000, 8:44 AM

Post #4 of 4 (473 views)
Re: Hit counter sort [In reply to] Can't Post

Hi

open( FILEIN, "+<cure.txt" ); #this will read and write to cure.txt
$_=<FILEIN>; # this will read the first line
seek(FILEIN,0,0); #This function positions the file pointer for FILEIN-> which in the case is the first line
$_++; #this increments the value in $_
truncate(FILEIN,0); #this will delete what ever is on the first line of the file
print FILEIN; #this will print the value of $_ to the cure.txt
print; # this will print $_ to the browser
close(FILEIN); #close the file cure.txt


Cure


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives