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:
switch statement?

 



lord_hairball
stranger

May 25, 2001, 12:53 PM

Post #1 of 3 (608 views)
switch statement? Can't Post

is there an equivalent of a C 'switch' statement in perl?



mhx
Enthusiast / Moderator

May 25, 2001, 1:32 PM

Post #2 of 3 (605 views)
Re: switch statement? [In reply to] Can't Post

No, this will be a feature of Perl 6.
Up to then, you can use the Switch Package available from CPAN.

-- Marcus



Kanji
User / Moderator

May 25, 2001, 6:15 PM

Post #3 of 3 (598 views)
Re: switch statement? [In reply to] Can't Post

Actually, there is a kludge available now ...


Code
  for ( $value ) { 
if ( /this/ ) { this() }
elsif ( /this/ ) { that() }
else { default() }
}

... often rewritten as ...

Code
  SWITCH: for ( $value ) { 
/this/ && do { this(); last SWITCH; };
/that/ && do { that(); last SWITCH; };
# ...
default();
}


 
 


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

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