Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PERL equivalent of VB Select Case

Status
Not open for further replies.

RottPaws

Programmer
Joined
Mar 1, 2002
Messages
478
Location
US
Is there a PERL equivalent of the Visual Basic SELECT CASE and the javascript Switch command?

Or do I just need to use if...elseif to do what I need?

_________
Rott Paws

...It's not a bug. It's an undocumented feature!!!
 
you can use the 'if' modifier

print "Too big!\n" if $_ > 100;

is this is of any help?

Regards
Duncan
 
if and else if will work.

I was just wondering if there was a similar alternative in PERL like there is in VB and javascript.

_________
Rott Paws

...It's not a bug. It's an undocumented feature!!!
 
From Programming Perl

There is no "official" switch statement in Perl

But as TIMTOWTDI

Code:
SWITCH: {
  /case1/ && do 
     { $abc=1;
       last SWITCH;
     };
  /case2/ && do 
     { $abc=2;
       last SWITCH;
     };  
  /case3/ && do 
     { $abc=3;
       last SWITCH;
     };       
  $no_match=1;
}

HTH
--Paul

For a more in depth answer check out the book
ISBN 1-56592-149-6


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top