Solved

inserting a random html snippet in an SSI tag?

Posted on 2000-04-20
2
317 Views
Last Modified: 2013-12-25
I've got the basic framework down for selecting from a list and displaying a random piece of arbitrary code, but much to my chagrin it always picks the last of them instead of a random one.  I know it's probably nothing more than a misplaced bit of punctuation, but I'm pulling my hair out over it...here's the code:

#!/usr/bin/perl
# Define Variable

@includedhtml = ("<random bit of html #1>",
      "<random bit #2>",
      "<random bit #3>");

srand(time ^ $$);
$num = rand(@includedhtml); # Pick a Random Number
print "Content-type: text/html\n\n";
print $includedhtml[$num];
print "\n";

Thanks everybody!
0
Comment
Question by:dibowkley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
chaduka earned 50 total points
ID: 2737302
I donno what's contained in the <random bit of HTML ##> part, but make sure they are well written and characters that need escaping are taken care of correctly.

See my alteration and another suggested solution to handle this product below:

#!/usr/bin/perl
# Define Variable

@includedhtml = ('<random bit of html #1>',
'<random bit #2>',
'<random bit #3>'); # Note the use of single quotes, double quotes are a bit pecky.

srand(); # The srand() func. uses time as a seed by default.

$num = int(rand(@includedhtml)); # Pick a Random Number
# the rand() function returns a floating point value. You need to get the integer part of this number for your app to know exactly what to pick from @includedhtml

print "Content-type: text/html\n\n";
print $includedhtml[$num];
print "\n";

--------------------------------------
I would suggest you do it like this:
1) Either have the bits of HTML in a file, as in:
 1:<htmltag>My text</htmltag>
 2:<htmltag2>My other text</htmltag2>
or put each bit of HTML in a seperate file e.g. 1.html will contain some HTML stuff, 2.html etc...
2) generate a random number using srand() and rand().
3) read the line or file corresponding to that number.

Note: seperate files will be a bit faster if your randmon bits count grow.

...or better still, try a database!!

Hope this helps, ...and have fun!!
0
 
LVL 84

Expert Comment

by:ozo
ID: 2738642
#The only bit of punctuation that should be giving you trouble is the ^
srand(time + $$); #would be a bit better
#or in 5.004 or later you can add a # before that line
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question