Back to articles
Beautiful Perl feature : fat commas, a device for structuring lists
NewsTools

Beautiful Perl feature : fat commas, a device for structuring lists

via Dev.toLaurent Dami

Beautiful Perl series This post is part of the beautiful Perl features series. See the introduction post for general explanations about the series. Today's topic is a Perl construct called fat comma , which is quite different from the trailing commas discussed in the last post . Fat comma: an introduction A fat comma in Perl is a construct that doesn't involve a typographic comma! Visually it consists of an expression followed by an arrow sign => and another expression. This is used in many contexts, the most common being for initializing hashes or for passing named parameters to subroutines: my %rect = ( x => 12 , y => 34, width => 20, height = > 10 ); draw_shape ( kind => ' rect ', coords => \ %rect , color => ' green '); A fat comma is semantically equivalent to a comma; the only difference with a regular comma is purely syntactic : if the left-hand side is a string that begins with a letter or underscore and is composed only of letters, digits and underscores, then that string does

Continue reading on Dev.to

Opens in a new tab

Read Full Article
3 views

Related Articles