Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Short and easy way to write if...elsif syntax

by davido (Cardinal)
on Aug 27, 2012 at 19:27 UTC ( #990043=note: print w/replies, xml ) Need Help??


in reply to Short and easy way to write if...elsif syntax

This is one of Perl's classical answers to the "switch" statement. In fact, if someone had simply created another name for "foreach" called "switch", we might have been spared the confusion that given has brought upon us.

foreach ( @array ) { /linux/ && do { print "This is a linux VM.\n"; next; }; /Windows/ && do { print "This is a Windows VM.\n"; next; }; /Other/ && do { print "I have no idea what it is.\n"; next; }; die "You shouldn't be seeing this: No pattern matched.\n"; }

Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990043]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2019-04-25 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (127 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!