Gossamer Forum
Home : General : Perl Programming :

else if, and print

Quote Reply
else if, and print
could someone tell me how to use elseif in a CGI script? Also how whould the print variable look if I wanted the CGI script to print to the browser "hi, welcome to my site!"

------------------
Patrick Chukwura
nytesoft.hypermart.net

[This message has been edited by niteridarz (edited March 25, 1999).]

[This message has been edited by niteridarz (edited March 25, 1999).]
Quote Reply
Re: else if, and print In reply to
For your first question:

Code:
if ($name eq "Mark Badolato") {
$city = "Scottsdale";
}
elsif ($name eq "Alex Krohn") { #Notice no "e" in elsif
$city = "Vancouver";
}
else {
$city = "Other";
}

For your second question:

#/usr/bin/perl
print "Content-type: text/html\n\n";
print "hi, welcome to my site!";


--mark


------------------
You can reach my by ICQ at UID# 8602162

Quote Reply
Re: else if, and print In reply to
Mark Badolato: I understand the print part but what does the else if do? Does it show it when you open the page or something?

Do you know a good script that I can start off with, something that is easy for first time CGI Perl programers? And do you know where I can see an example of it?

Also do you make your own CGI scripts, if so how did you learn?

------------------
Patrick Chukwura
http://nytesoft.hypermart.net
Quote Reply
Re: else if, and print In reply to
In the above, the if/elsif/else routine has nothing to do with the print. they're 2 seperate examples.

What it is doing is saying "ok, if the user name is equal to this, do this. No? ok, well if it's equal to THIS, do THIS. Still no? ok, just go with the default."

Just conditional loops. you could use it with print

if condition {
print "thing 1";
}
elsif condition2 {
print "thing 2";
}
else {
print "standard default thing";
}

The best way to learn is to look at premade sttuff (start with simpler things) and see what is happening. when you have a good idea, start changing things and se if you get the desired results.

I would also recommend looking at online perl tutorials.

--mark

--Mark
Quote Reply
Re: else if, and print In reply to
Thanx, I will try looking at the tutorials at www.cgi-center.com

------------------
Patrick Chukwura
http://nytesoft.hypermart.net