DEV Community

Discussion on: Switching up my switches in Perl

Collapse
 
drbaggy profile image
James Smith

Surely
if(/^abc/) {
last;
}
is more readable and in this case shorter (10 vs 13 symbols) than the horrible

/^abc/ and do {
last;
}

But I do agree that the lookup is better... but sometimes the best is the stacked ternaries if all the brace is doing is assigning...

Collapse
 
mjgardner profile image
Mark Gardner

I've amended the post to add an example of stacked ternaries.

Collapse
 
mjgardner profile image
Mark Gardner

Either is fine—I prefer less punctuation, especially in a punctuation-happy language like Perl. And stacked ternaries are great if all you're doing is assigning to the same variable.