if and else


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers if and else
# 1  
Old 04-30-2008
if and else

Hello,

I am using
Quote:
my $info=url_param("info");
to fetch the word that is written after script.cgi?info=word.

I'm looking to have the program take that word and use it in a
if, else purpose.

I would like to be able to write $show somewhere in the program and with that the word behind info is used to decide witch of the two words, open or closed, are written.

That is:

if info=yes. Write open
if info=no. Write closed

Is this a difficult thing to archive?
# 2  
Old 04-30-2008
If you are not at all familiar with the syntax, how are you going to pull off writing the rest of the script?

Code:
if ($info eq "yes") { print "open"; } else { print "closed"; }

There's a shorthand which is a bit funny, but very convenient in some situations:

Code:
print ($info eq "yes" ? "open" : "closed");

This is assuming you are talking about Perl here. I even wrote a long reply about shell scripting before I realized you are probably asking about Perl.

Last edited by era; 04-30-2008 at 01:46 PM.. Reason: Shorthand with ternary operator
# 3  
Old 04-30-2008
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question