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:
"or" statements

 



AlanBell
Deleted

Jan 2, 2000, 6:02 PM

Post #1 of 2 (3538 views)
"or" statements Can't Post

I couldn't believe I got two responses so quickly to my last question so here comes another.
I want to be able to "withdraw" valid numbers.
It is easy to do with just one number.

if ($number == 1003118)
{
print "Content-type: text/html\n\n";
print <<"EXIT";
<body bgcolor="ffffff">
This code is no longer valid.
EXIT
exit;
}

But how do I add other numbers to this? I thought that the following should have worked, but it didn't. Is there a limit on how long an expression can be?

if ($number == 1003118 or 1005121 or 1007126)
{
print "Content-type: text/html\n\n";
print <<"EXIT";
<body bgcolor="ffffff">
This code is no longer valid.
EXIT
exit;
}

One other matter. When I try and print an expression that includes "$", it doesn't print. I tried substituting "&36;" but this didn't work.
I feel as if the learning curve is just getting steeper!
Thanks again,
Alan



Borderline
Deleted

Jan 2, 2000, 7:16 PM

Post #2 of 2 (3538 views)
Re: "or" statements [In reply to] Can't Post

As you are going to find during your studies of Perl TIMTOWTDI (Tere Is More Than One Way To Do It) and there always is.
One way would to store the numbers into an Array like this<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


@nums = (1003118, 1005121, 1007126);</pre><HR></BLOCKQUOTE>
You could populate that array in any number of ways and then just use a loop to go through the values like this<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


for $item(@nums) {
if ($number == $item) {
print "The code is not longer valid";
exit
}
}</pre><HR></BLOCKQUOTE>
Or is you want to use the 'or' operator like you did and just hard code the numbers into the code<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


if (($number == 1003118) or
($number == 1005121) or
($number == 1007126))
{
print "The code is not longer valid";
exit
}</pre><HR></BLOCKQUOTE>
The ( ) around each comparison is not nesisary in this case but it makes it more readable.
As I said before I am sure you can find many ways to do these comparisons.

Have Fun!
Scott

 
 


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

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