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:
Random Stuff

 



SaiyanM
User

Mar 23, 2001, 3:58 PM

Post #1 of 2 (295 views)
Random Stuff Can't Post

If anyone can help me on this, i would greatly appreciate it... I made a random button showing script (which shows buttons of different sites to help their traffic). However, a random button doesn't show up. Here is the code...


bexchange.cgi:::::::::::::::::::::::::::::::::::;
#!/usr/local/bin/perl/
##########################
# Saiyan Menacy Button Exchange V1.0
# 1999-2001 ChibiGuy Productions
# Don't bother stealing this, what good is it gonna do?
# E-mail me at Saiyan M@hotmail.com
# Feel free to re-distribute this script as many times as you want
# however, please do not try to sell this script
# and if you change the script to your liking,
# let me see it and ill tell you if it is okay
##########################

##Variables
use CGI qw/:standard/;
$sitename = param('sitename');
$siteurl = param('url');
$buttonurl = param('buttonurl');



##Add the button snippet to the .txt file
open(addbutton, ">>/data1/virtualave.net/saiyanh/public_html/cgi-bin/bexchange/buttons.txt");
print addbutton<<END;
<table width="92" border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="Black"><table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="white"><a href="$siteurl"><img src="$buttonurl" border="0" width="88" height="31" alt="$sitename"></a></tD></tR><tr><td bgcolor="white"><center><font face="arial" size="1"><a href="http://saiyanh.virtualave.net/cgi-bin/bexchange/add.html">SMenacy Button Exchange</a></center></td></tR></table></td></tR></table>

END
close(addbutton);



##Thanks
print "Content-type: text/html\n\n";
print <<THANKS;
Thanks for joining my exchange. Heres the snippet of coding that should go on your site... <!--#include virtual="http://saiyanh.virtualave.net/cgi-bin/bexchange/random.cgi" -->
THANKS

This part works fine but the next file doesnt show anything...


random.cgi:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#!/usr/local/bin/perl/
#########DONT CHANGE THIS FILE, VERY CRUCIAL TO THE WHOLE PROCESS
$buttonsfile = "/cgi-bin/bexchange/buttons.txt";

print "Content-type: text/html\n\n";
open (BUTTONS,$buttonsfile);
flock (BUTTONS,2); seek(BUTTONS,0,0);
@BUTTONS = <BUTTONS>;
close(BUTTONS);
$buttons = @BUTTONS;
$button = rand $buttons;
print $BUTTONS[$button];


I also tried
#!/usr/local/bin/perl/
#########DONT CHANGE THIS FILE, VERY CRUCIAL TO THE WHOLE PROCESS
srand; rand($.) < 1 && ($line = $_) while <>;

but it still doesnt work...


Does anyone know the problem?



(This post was edited by SaiyanM on Mar 23, 2001, 3:29 PM)


kencl
User

Mar 24, 2001, 1:04 PM

Post #2 of 2 (285 views)
Re: Random Stuff [In reply to] Can't Post

rand returns a fractional value. You should change that to:

Code
$button = int(rand $buttons);

As it is, your trying to read something like:

Code
$BUTTONS[7.3892208732156];

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!

 
 


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

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