http://www.perlmonks.org?node_id=990043


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