--- Luinrandir Hernson <[EMAIL PROTECTED]> wrote:
> srand;
> $A = int (rand (4))
> if ($A eq '0') {print "<BODY BACKGROUND=\"images/celtknt0.jpg\">\n"};
> if ($A eq '1') {print "<BODY BACKGROUND=\"images/celtknt1.jpg\">\n"};
> if ($A eq '2') {print "<BODY BACKGROUND=\"images/celtknt2.jpg\">\n"};
> if ($A eq '3') {print "<BODY BACKGROUND=\"images/celtknt3.jpg\">\n"};

In addition to previous comments:

1.  Perl no longer requires that you call srand before rand.  It calls it for you.

2.  If you need to interpolate escape characters (like '\n' or variables), but you 
don't want to
escape a bunch of double quotes, try using something like qq!insert string here!.

3.  Whenever you see repetitive code, it's a good idea to try to try to factor out the 
common
elements.  The following does what your code is supposed to do:

my $A = int (rand (4));
print qq!<BODY BACKGROUND="images/celtknt${A}.jpg">n!;

As a side note, the curly brackets {} around the A in the interpolated string force 
Perl to
recognize that $A is the variable in question.  It's not needed here, but if the $A was
immediately followed by letters ("images/celtknt$Apic.jpg"), the Perl would need to 
curly braces
so that it knows *which* letters are part of the variable name.

Hope this helps!

Cheers,
Curtis Poe


=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

Reply via email to