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: Intermediate:
Conditional hash results...possible?

 



S_Shrum
User

Nov 4, 2001, 11:28 PM

Post #1 of 2 (447 views)
Conditional hash results...possible? Can't Post

Is it possible to do something like this:


Code
my hash% = (   test   =>   if ( condition ) { this; } else { that; } );

...and if so, how would you syntax the line so TEST gets the value of the cooresponding result.

TIA

Sean Shrum
sean@shrum.net
http://www.shrum.net/programming - Free Perl Scripts
http://www.shrum.net/soaring - Sailplane Soaring and Combat


yapp
User

Nov 5, 2001, 12:07 AM

Post #2 of 2 (446 views)
Re: Conditional hash results...possible? [In reply to] Can't Post

C, Java and Perl support the following inline-if syntax:

Code
(continion ? return value if true : return value if false) 

# like:
$Value = ($x == 3 ? 3 : 2);

# Perl has also has an other cool syntax (not in C or java)
($x == 45 ? $Y : $Z) = 34;
# which assigns 34 to $Y or $X if $X equals 45


 
 


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

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