PBP: 049 Lists

This best practice is a simple suggestion: Put every raw list in parenthesis.  It’s good.The book provides an example of why this is important.  There’s at least one other case that bit me at the office:


for my $bar qw/ one two three four / {

print "$bar is yay!\n";

}

This changed, so that qw no longer worked as a list with for, and you needed to add parens to make the for loop use the list:


for my $bar (qw/ one two three four /) {

print "$bar is yay!\n";

}

We had old crufty code that did this at work, which we had to clean up.

I did find a blog post where the poster was extremely unhappy about this change.  I could not understand his ire then, and don’t now, even though I had to actively make code changes to allow the bug.

Anyway, use those list parens.  (The example I gave isn’t great, because it isn’t actually a list paren, but it looks like one.)

Leave a Reply