{"id":20757,"date":"2022-11-10T20:29:35","date_gmt":"2022-11-10T14:59:35","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/"},"modified":"2022-11-10T20:29:35","modified_gmt":"2022-11-10T14:59:35","slug":"solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/","title":{"rendered":"[Solved] When is it advantageous to use curly braces for dereferencing in Perl?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-44060022\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"44060022\" data-parentid=\"44057901\" data-score=\"8\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>You are conflating two concepts.<\/p>\n<p>The first thing you need to learn is that there is there are <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.perlmonks.org\/?node_id=977408\">two syntaxes<\/a> for deferencing.<\/p>\n<pre><code> Circumfix            Postfix\n \"Block syntax\"       \"Arrow syntax\"\n\n $BLOCK               EXPR-&gt;$*\n @BLOCK               EXPR-&gt;@*\n $BLOCK[$i]           EXPR-&gt;[$i]\n &amp;BLOCK()             EXPR-&gt;()\n ...                  ...\n<\/code><\/pre>\n<p>Furthermore, both syntax have a simplification available to them.<\/p>\n<hr>\n<p>Your array example is an example of a simplification available to the block syntax. If the block contains nothing but a simple scalar (<code>$ref<\/code>), you can omit the curlies.<\/p>\n<pre><code>${ $ref }                   # Can be simplified to $$ref\n@{ $ref }                   # Can be simplified to @$ref\n${ $ref }[$i]               # Can be simplified to $$ref[$i]\n&amp;{ $ref }()                 # Can be simplified to &amp;$ref()\n<\/code><\/pre>\n<p>If the block contains anything else, you can&#8217;t avail yourself of this simplification.<\/p>\n<pre><code>@{ $refs{$key} }            # Can't be simplified\n@{ f() }                    # Can't be simplified\n@{ my $ref = f(); $ref }    # Can't be simplified\n\n&amp;{ $refs{$key} }()          # Can't be simplified\n&amp;{ f() }()                  # Can't be simplified\n&amp;{ my $ref = f(); $ref }    # Can't be simplified\n<\/code><\/pre>\n<hr>\n<p>Your code ref example, on the other hand, is an example of the switching from the block syntax to the arrow syntax. It&#8217;s not a simplification <em>per se<\/em>.<\/p>\n<pre><code>\"Block syntax\"               \"Arrow syntax\"\n&amp;{ $hash{frogs} }()    \u21d2     $hash{frogs}-&gt;()\n<\/code><\/pre>\n<hr>\n<p>Your code ref example is also an example of a simplification available to the arrow syntax. When the arrow is between <code>[...]<\/code> or <code>{...}<\/code>, and <code>[...]<\/code>, <code>{...}<\/code> or <code>(...)<\/code>, the arrow can be omitted.<\/p>\n<pre><code>$ref-&gt;{$k}-&gt;[$i]            # Can be simplified to $ref-&gt;{$k}[$i]\n$ref-&gt;{$k}-&gt;{$l}            # Can be simplified to $ref-&gt;{$k}{$l}\n$ref-&gt;{$k}-&gt;()              # Can be simplified to $ref-&gt;{$k}()\n\n$ref-&gt;[$i]-&gt;[$j]            # Can be simplified to $ref-&gt;[$i][$j]\n$ref-&gt;[$i]-&gt;{$k}            # Can be simplified to $ref-&gt;[$i]{$k}\n$ref-&gt;[$i]-&gt;()              # Can be simplified to $ref-&gt;[$i]()\n<\/code><\/pre>\n<hr>\n<p>Finally, which should you use?<\/p>\n<p>The choice of whether to the block syntax or the arrow syntax is one of personal preference, but the following conventions are usually followed to maximize readability:<\/p>\n<ul>\n<li>\n<p>The block syntax is preferred for scalar, array and hash dereferences.<\/p>\n<pre><code>$$ref                is generally preferred over     $ref-&gt;$*\n@$ref                is generally preferred over     $ref-&gt;@*\n%$ref                is generally preferred over     $ref-&gt;%*\n<\/code><\/pre>\n<\/li>\n<li>\n<p>When using the block syntax, curlies are omitted if possible.<\/p>\n<pre><code>$$ref                is generally preferred over     ${ $ref }\n@$ref                is generally preferred over     @{ $ref }\n%$ref                is generally preferred over     %{ $ref }\n<\/code><\/pre>\n<\/li>\n<li>\n<p>The arrow syntax is preferred for array element, hash element and code dereferences.<\/p>\n<pre><code>$ref-&gt;[...]          is generally preferred over     $$ref[...]\n$ref-&gt;{...}          is generally preferred over     $$ref{...}\n$ref-&gt;(...)          is generally preferred over     &amp;$ref(...)\n<\/code><\/pre>\n<\/li>\n<li>\n<p>The arrow itself is omitted when possible, except when used to deference code.<\/p>\n<pre><code>$ref-&gt;[...][...]     is generally preferred over     $ref-&gt;[...]-&gt;[...]\n$ref-&gt;[...]{...}     is generally preferred over     $ref-&gt;[...]-&gt;{...}\n$ref-&gt;[...]-&gt;(...)   is generally preferred over     $ref-&gt;[...](...)\n$ref-&gt;{...}[...]     is generally preferred over     $ref-&gt;{...}-&gt;[...]\n$ref-&gt;{...}{...}     is generally preferred over     $ref-&gt;{...}-&gt;{...}\n$ref-&gt;{...}-&gt;(...)   is generally preferred over     $ref-&gt;{...}(...)\n<\/code><\/pre>\n<\/li>\n<li>\n<p>The block syntax is preferred for array slices and hash slices. It&#8217;s far less readable than the arrow syntax, but the arrow syntax for these requires Perl 5.24.<\/p>\n<pre><code>@$ref[...]           is generally preferred over     $ref-&gt;@[...]\n@$ref{...}           is generally preferred over     $ref-&gt;@{...}\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">5<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved When is it advantageous to use curly braces for dereferencing in Perl? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] You are conflating two concepts. The first thing you need to learn is that there is there are two syntaxes for deferencing. Circumfix Postfix &#8220;Block syntax&#8221; &#8220;Arrow syntax&#8221; $BLOCK EXPR-&gt;$* @BLOCK EXPR-&gt;@* $BLOCK[$i] EXPR-&gt;[$i] &amp;BLOCK() EXPR-&gt;() &#8230; &#8230; Furthermore, both syntax have a simplification available to them. Your array example is an example of &#8230; <a title=\"[Solved] When is it advantageous to use curly braces for dereferencing in Perl?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/\" aria-label=\"More on [Solved] When is it advantageous to use curly braces for dereferencing in Perl?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[442],"class_list":["post-20757","post","type-post","status-publish","format-standard","hentry","category-solved","tag-perl"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] When is it advantageous to use curly braces for dereferencing in Perl? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] When is it advantageous to use curly braces for dereferencing in Perl? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] You are conflating two concepts. The first thing you need to learn is that there is there are two syntaxes for deferencing. Circumfix Postfix &quot;Block syntax&quot; &quot;Arrow syntax&quot; $BLOCK EXPR-&gt;$* @BLOCK EXPR-&gt;@* $BLOCK[$i] EXPR-&gt;[$i] &amp;BLOCK() EXPR-&gt;() ... ... Furthermore, both syntax have a simplification available to them. Your array example is an example of ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-10T14:59:35+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] When is it advantageous to use curly braces for dereferencing in Perl?\",\"datePublished\":\"2022-11-10T14:59:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/\"},\"wordCount\":266,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"perl\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/\",\"name\":\"[Solved] When is it advantageous to use curly braces for dereferencing in Perl? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-11-10T14:59:35+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] When is it advantageous to use curly braces for dereferencing in Perl?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] When is it advantageous to use curly braces for dereferencing in Perl? - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] When is it advantageous to use curly braces for dereferencing in Perl? - JassWeb","og_description":"[ad_1] You are conflating two concepts. The first thing you need to learn is that there is there are two syntaxes for deferencing. Circumfix Postfix \"Block syntax\" \"Arrow syntax\" $BLOCK EXPR-&gt;$* @BLOCK EXPR-&gt;@* $BLOCK[$i] EXPR-&gt;[$i] &amp;BLOCK() EXPR-&gt;() ... ... Furthermore, both syntax have a simplification available to them. Your array example is an example of ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/","og_site_name":"JassWeb","article_published_time":"2022-11-10T14:59:35+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] When is it advantageous to use curly braces for dereferencing in Perl?","datePublished":"2022-11-10T14:59:35+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/"},"wordCount":266,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["perl"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/","url":"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/","name":"[Solved] When is it advantageous to use curly braces for dereferencing in Perl? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-11-10T14:59:35+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-when-is-it-advantageous-to-use-curly-braces-for-dereferencing-in-perl\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] When is it advantageous to use curly braces for dereferencing in Perl?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/20757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=20757"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/20757\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=20757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=20757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=20757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}