Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Link Displayer

Status
Not open for further replies.

Ectoman

Technical User
Nov 30, 2001
8
US
I downloaded a script off the net that will display a random link taken from a text file. Here is what it currently shows:

Code:
open (QUOTEFILE, &quot;<$data_location/$file&quot;) || die print &quot;Could not open ad links file&quot;;
	@line=<QUOTEFILE>;
	close (QUOTEFILE);
	srand;
	$array = $line[int rand(@line)];

	@adlink = split (/\|/, $array);

	print &quot;$adlink[0] &quot; if ($adlink[0]);
	print &quot;<A HREF=\&quot;$adlink[2]\&quot;&quot;;
	print &quot; TARGET=\&quot;$adlink[3]\&quot;&quot; if ($adlink[3]);
	print &quot;>$adlink[1]</A>&quot;;
	print &quot; $adlink[4]&quot; if ($adlink[4]);

exit;

I have changed the script to my liking, so it only displays the title and url. The script works great, however it still is not up to my liking. I am wondering if it is possible to display 5 different links taken from the same data file. These links should be different from all the other displayed. Is this possible?

I was thinking maybe srand could choose a line to display, then it could add one number and display the next line, and add another number and another line. Is that possible?

I am completely clueless with this.
 
sure.
make a loop, and have that loop through once for every link you want to display.
inside this loop, have your call to rand, but this time, instead of just accessing the element of the array of addresses, have it splice out the correct element. the usage of splice is:
splice(@arr, $index, $offset, ($replacements...))
,
so the index will be the call to rand, the offset will be one, and there won't be any replacements.

i hope this is enough info to get you through this.
good luck.
stillflame &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Sorry, but it was not. I am new to perl, and am still learning new things. It would be easier for me if you were to add the part I need to the program code above. I learn best when I see it in a finished programs. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top