Change: . After reading the answers, I think the answer is “don't do this,” so I marked the corresponding answer as an official answer.
Is there an easy way to get emacs to display perl switch instructions like perldoc.perl.org go to page ?
Here's the formatting on perldoc.perl.org:
use Switch;
switch ($val) {
case 1 { print "number 1" }
case "a" { print "string a" }
case [1..10,42] { print "number in list" }
case (\@array) { print "number in list" }
case /\w+/ { print "pattern" }
case qr/\w+/ { print "pattern" }
case (\%hash) { print "entry in hash" }
case (\&sub) { print "arg to subroutine" }
else { print "previous case not true" }
}
Here in the fragment formatting is performed cperl-modeafter M-x indent-region:
use Switch;
switch ($val) {
case 1 { print "number 1" }
case "a" { print "string a" }
case [1..10,42] { print "number in list" }
case (\@array) { print "number in list" }
case /\w+/ { print "pattern" }
case qr/\w+/ { print "pattern" }
case (\%hash) { print "entry in hash" }
case (\&sub) { print "arg to subroutine" }
else { print "previous case not true" }
}
I have an inexplicable desire to stick with if-elsif constructs ...
ps. I think this describes the desired process, but it seems like it will take some time for parsing.