
Beautiful Perl feature: trailing commas
Beautiful Perl series This post is part of the beautiful Perl features series. See the introduction post for general explanations about the series. The last two posts about lexical scoping and dynamic scoping addressed deep subjects and therefore were very long; for this time, we'll discuss trailing commas , a much lighter subject ... that nevertheless deserves detailed comments! Trailing commas, basic principle Programming languages that support trailing commas are able to parse a list like (1, 2, 3, 5, 8,) without generating an error. In other words, it is legal to put a comma after the last item in the list; that comma is a no-op, so the list above is equivalent to (1, 2, 3, 5, 8) . Of course the trailing comma is optional, not mandatory. When it appears on a single line, like in that example, the trailing comma seems ridiculous; but the interest is when the list is written on several lines: my @fruits = ( " apples ", " oranges ", " bananas ", ); Here the trailing comma facilitates
Continue reading on Dev.to
Opens in a new tab



